Given a number N. The task is to complete the function convertFive() which replace all zeros in the number with 5 and returns the number.
Input:
The first line of input contains an integer T, denoting the number of testcases. Then T testcases follow. Each testcase contains a single integer N denoting the number.
Output:
The function will return integer where all zero's are converted to 5.
User Task:
Since this is a functional problem you don't have to worry about input, you just have to complete the function convertFive().
Constraints:
1 <= T <= 103
1 <= N <= 104
Example:
Input
2
1004
121
Output
1554
121
Solution
int convertFive(int n)
{
//Your code here
int i,j,k,l,sum;
vector<int>v;
l=n;
sum=0;
while(n!=0)
{
k=n%10;
if(k==0)
{
v.push_back(5);
}
else
{
v.push_back(k);
}
n=n/10;
}
if(l==0)
{
return l;
}
else
{
for(i=v.size()-1;i>=0;i--)
{
sum=sum*10+v[i];
}
return sum;
}
}
0 comments:
Post a Comment