#include <stdio.h> #include <string.h> struct big { int num[200]; int len; }; struct big c; void jian(struct big a,struct big b) { for(int i=0;i<a.len;i++) { if(a.num[i]<b.num[i]) { a.num[i+1]--; a.num[i]+=10; } c.num[i]=a.num[i]-b.num[i]; c.len++; } for(int i=c.len-1;i>=0;i--) { if(c.num[i]!=0) { break; } else { c.len--; } } } int main() { struct big a,b; int n; scanf("%d",&n); getchar(); for(int i=0;i<n;i++) { for(int j=0;j<200;j++) { a.num[j]=0; b.num[j]=0; c.num[j]=0; } a.len=0; b.len=0; c.len=0; char str1[200]={'\0'},str2[200]={'\0'}; gets(str1); for(int j=strlen(str1)-1;j>=0;j--) { a.num[a.len]=str1[j]-'0'; a.len++; } gets(str2); for(int j=strlen(str2)-1;j>=0;j--) { b.num[b.len]=str2[j]-'0'; b.len++; } int len=a.len<b.len?b.len:a.len; len--; int flag=1; while(len>=0) { if(a.num[len]==b.num[len]) { len--; } else { if(a.num[len]>b.num[len]) { flag=1; } else { flag=0; } break; } } if(flag) { jian(a,b); printf("Case #%d:\n",i+1); if(c.len==0) { printf("0"); } else { for(int j=c.len-1;j>=0;j--) { printf("%d",c.num[j]); } } printf("\n"); } else { jian(b,a); printf("Case #%d:\n",i+1); printf("-"); if(c.len==0) { printf("0"); } for(int j=c.len-1;j>=0;j--) { printf("%d",c.num[j]); } printf("\n"); } memset(str1,0,sizeof) } } /* Main.c: In function 'main': Main.c:56:3: warning: 'gets' is deprecated [-Wdeprecated-declarations] gets(str1); ^~~~ In file included from Main.c:1: /usr/include/stdio.h:583:14: note: declared here extern char *gets (char *__s) __wur __attribute_deprecated__; ^~~~ Main.c:62:3: warning: 'gets' is deprecated [-Wdeprecated-declarations] gets(str2); ^~~~ In file included from Main.c:1: /usr/include/stdio.h:583:14: note: declared here extern char *gets (char *__s) __wur __attribute_deprecated__; ^~~~ Main.c:125:23: error: expected expression before ')' token memset(str1,0,sizeof) ^ */ |
Double click to view unformatted code.