注意格式(Case的首字母大寫、各類空格、每一行之間有空行,最後一行沒有空行)!java
給出幾組測試數據:web
6import java.util.*; import java.io.*; import java.math.*; class Main { public static BigInteger plus(BigInteger a, BigInteger b) { BigInteger c; c = a.add(b); return c; } public static void main(String args[]) { Scanner cin = new Scanner(System.in); int T, i; BigInteger a,b; T = cin.nextInt(); i = 1; while((T--) > 0) { a = cin.nextBigInteger(); b = cin.nextBigInteger(); System.out.println("Case "+ i +":"); System.out.println(a + " + "+ b + " = "+ plus(a, b)); i++; if(T > 0) System.out.println(); } } }
C code測試
#include<stdio.h> #include<string.h>
#include<stdlib.h>
void solve() { int n,i,j,k,flag,t,cas,L; char a[1001],b[1001],c[1002]; scanf("%d",&n); getchar(); cas=1; while(n--) { flag=0; memset(a,'\0',sizeof(a)); memset(b,'\0',sizeof(b)); memset(c,'\0',sizeof(c)); scanf("%s",a); scanf("%s",b); printf("Case %d:\n",cas); printf("%s",a); printf(" + "); printf("%s",b); printf(" = "); strrev(a); strrev(b); k=i=0; L=(strlen(a)>strlen(b)?strlen(b):strlen(a)); while(i<L) { t=(a[i]-'0')+(b[i]-'0')+flag; flag=(t>=10?1:0); c[k++]=t%10+'0'; i++; } if(a[i]=='\0') { while(b[i]!='\0') { t=b[i++]-'0'+flag; c[k++]=t%10+'0'; flag=(t>=10?1:0); } } else { while(a[i]!='\0') { t=a[i++]-'0'+flag; c[k++]=t%10+'0'; flag=(t>=10?1:0); } } if(flag) c[k]='1'; else k--; while(k>=0) { printf("%c",c[k]); k--; } printf("\n"); if(n>0) printf("\n"); cas++; } } int main() { solve(); return 0; }