K L University Freshman Engineering Department: A Project Based Lab Report On Lucky Transformation
K L University Freshman Engineering Department: A Project Based Lab Report On Lucky Transformation
On
LUCKY TRANSFORMATION
SUBMITTED BY:
2000031537 G.KARTHIKEYA
B.PREMALATHA WILLIAMS
ASST.PROFESSOR(CSE)
KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES
CERTIFICATE
B.PREMALATHA WILLIAMS
Dr. D.HARITHA
ACKNOWLEDGEMENTS
Name: G.KARTHIKEYA
ABSTRACT
Petya loves lucky numbers. Everybody knows that lucky numbers are positive
integers whose decimal representation contains only the lucky digits 4 and 7. For
example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of n digits without leading zeroes. He represented it
as an array of digits without leading zeroes. Let's call it d. The numeration starts
with 1, starting from the most significant digit. Petya wants to perform the
following operation k times: find the minimum x (1 ≤ x < n) such that dx = 4 and
dx + 1 = 7, if x is odd, then to assign dx = dx + 1 = 4, otherwise to assign dx = dx +
1 = 7. Note that if no x was found, then the operation counts as completed and the
array doesn't change at all.
You are given the initial number as an array of digits and the number k. Help Petya
find the result of completing k operations.
Input
The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 109) — the
number of digits in the number and the number of completed operations. The
second line contains n digits without spaces representing the array of digits d,
starting with d1. It is guaranteed that the first digit of the number does not equal
zero.
Output
In the single line print the result without spaces — the number after the k
operations are fulfilled
INDEX
S.NO TITLE PAGENO
1 Introduction <pageno>
5 Implementation <pageno>
8 Conclusion <pageno>
INTRODUCTION
➢ SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Turbo-C
Operating system: Windows Xp or later.
➢ HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:
RAM :8 GB
1.start
2.analyse the given lucky numbers
(4 and 7)
3.develop the formation
4.complete coding
5.stop
IMPLEMENTATION
#include<stdio.h>
#include<string.h>
int n, k, length;
char s[1000];
int main()
{
scanf("%d %d",&n,&k);
scanf("%s",s);
length=strlen(s);
for(int i=0;i<length-1;i++)
{
if(k==0) break;
if(s[i]=='4'&&s[i+1]=='7')
{
if(i>0&&s[i-1]=='4')
{
if(i%2){
if(k%2) s[i]='7';
k=0;continue;
}
}
if(i%2) s[i]='7';
else s[i+1]='4';
k--;
}
}
printf("%s",s);
return 0;
}
INTEGRATION AND SYSTEM TESTING
OUTPUTS
Screen Shots:
CONCLUSION
We have successfully completed the project “LUCKY TRANSFORMATION” in
simple way. And given all test cases and everything is passed