-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertFive-GFGQ.cpp
More file actions
74 lines (60 loc) · 1.48 KB
/
ConvertFive-GFGQ.cpp
File metadata and controls
74 lines (60 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Replace all 0's with 5
Stand out from the crowd. Prepare with Complete Interview Preparation
Given a number N. The task is to complete the function convertFive() which replaces all zeros in the number with 5 and returns the number.
Example:
Input
2
1004
121
Output
1554
121
Explanation:
Testcase 1: At index 1 and 2 there is 0 so we replace it with 5.
Testcase 2: There is no,0 so output will remain the same.
Input:
The first line of input contains an integer T, denoting the number of test cases. Then T test cases follow.
Each test case contains a single integer N denoting the number.
Output:
The function will return an integer where all zero's are converted to 5.
Your 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
*/
//{ Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
// Driver program to test above function
// } Driver Code Ends
class Solution{
public:
/*you are required to complete this method*/
int convertFive(int n)
{
//Your code here
string str=to_string(n);
int res=0;
for(int i=0;i<str.size();i++){
if(str[i]=='0') res=res*10+5;
else res=res*10+(str[i]-'0');
}
return res;
}
};
//{ Driver Code Starts.
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
Solution obj;
cout<<obj.convertFive(n)<<endl;
}
}
// } Driver Code Ends