zoj 2001 Adding Reversed Numbers

水题~,就是给你两个数,先把这两个数翻转,然后将这两个数相加在翻转输出,注意不要输出前导零,但中间的零要输出。

代码:

 1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4 #include<iostream>
5 using namespace std;
6 int reverse(int x)
7 {
8 int s=0;
9 while(x)
10 {
11 s=s*10+x%10;
12 x=x/10;
13 }
14 return s;
15 }
16 int main()
17 {
18 int a,b,c,t;
19 cin>>t;
20 while(t--)
21 {
22 cin>>a>>b;
23 a=reverse(a);
24 b=reverse(b);
25 c=a+b;
26 int f=0;
27 while(c)
28 {
29 int m=c%10;
30 if(m||f)
31 {
32 printf("%d",m);
33 f=1;
34 }
35 c=c/10;
36 }
37 cout<<endl;
38 }
39 return 0;
40 }



原文地址:https://www.cnblogs.com/misty1/p/2277492.html