Reverse The Number Problem Code: FLOW007Submit
Given an Integer N, write a program to reverse it.
Input
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
Output
For each test case, display the reverse of the given number N, in a new line.
Constraints
- 1 ≤ T ≤ 1000
 - 1 ≤ N ≤ 1000000
 
Sample Input 1
4
12345
31203
2123
2300
Sample Output 1
54321
30213
3212
32
------------------------------------------------------
solution in c++#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int t, n;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		string s = to_string(n);
		reverse(s.begin(), s.end());
		while (s.at(0) == '0')
		{
			s.erase(s.begin());
		}
		cout << s;
		cout << "\n";
	}
	return 0;
}
No comments:
Post a Comment