洛谷:P1307
OJ: T1089
代码实现:
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 | /**************************************************************** * Description: 2011年普及组 数字反转 * Author: Alex Li * Date: 2022-10-03 21:55:00 * LastEditTime: 2024-10-09 22:13:17 ****************************************************************/ #include <iostream> using namespace std; int main(){ int n,a[11],c,i,j; bool b = true; cin>>n; if(n==0){ cout<<n; return 0; }; if(n<0){ b=false; n=-n; } for (i = 1; i <=11; i++){ c=n%10; a[i]=c; n=n/10; if(n==0)break; } for ( j =1; j <=i; j++)if(a[j]!=0)break; if(!b)cout<<'-'; for (int k =j; k <=i; k++)cout<<a[k]; return 0; } |