数字颠倒

目光所至,皆是美景!

描述:

输入一个整数,将这个整数以字符串的形式逆序输出

程序不考虑负数的情况,若数字含有0,则逆序形式也含有0,如输入为100,则输出为001

my codes:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     string s;
 6     while(cin>>s)
 7     {
 8         int len=s.size();
 9         for(int i=len-1;i>=0;i--) cout<<s[i];
10         cout<<endl;
11     }
12     return 0;
13 }

many beautiful ways:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	while(cin>>s) reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

  

 1 #include<bits/stdc++>h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     while(cin>>n)
 7     {
 8         string s=to_string(n);   //迅速地实现数的字符串化,那么,一个问题来了喽: 如何将一个字符串数字化来嘞!
 9         reverse(s.begin(),s.end());
10         cout<<s<<endl;
11     }
12     return 0;
13 }
原文地址:https://www.cnblogs.com/dragondragon/p/11195268.html