#include<stdio.h> #include<string.h> #include<stdlib.h> char a[10]; char b[10]; char c[10]; int a1,b1,s1,a2,b2,s2; void reverse(char *a) { int len=strlen(a); for(int i=0,j=len-1;i<j;++i,--j) { int t=a[i]; a[i]=a[j]; a[j]=t; } } int main(int argc, char *argv[]) { int n; while(~scanf("%d",&n)) { for(int i=0;i<n;++i) { scanf("%s%s",a,b); a1=atoi(a); b1=atoi(b); s1=a1+b1;//和 reverse(a); reverse(b); a2=atoi(a); b2=atoi(b); s2=a2+b2;//反转的和 int j=0; while(s1) { c[j++]=s1%10+'0'; s1/=10; } c[j]='\0';//和的反转 s1=atoi(c); if(s1==s2) { reverse(c); printf("%s\n",c); } else printf("NO\n"); } } return 0; } /************************************************************** Problem: 1089 User: kirchhoff Language: C Result: Accepted Time:0 ms Memory:912 kb ****************************************************************/
原文地址:http://blog.csdn.net/wdkirchhoff/article/details/42241383