1 条题解
-
0
C :
#include<stdio.h> #include<string.h> void Add(char *str1,char *str2,char *str3) { int i,j,i1,i2,tmp,carry; int len1=strlen(str1),len2=strlen(str2); char ch; i1=len1-1; i2=len2-1; j=carry=0; for(;i1>=0&&i2>=0;++j,--i1,--i2) { tmp=str1[i1]-'0'+str2[i2]-'0'+carry; carry=tmp/10; str3[j]=tmp%10+'0'; } while(i1>=0) { tmp=str1[i1--]-'0'+carry; carry=tmp/10; str3[j++]=tmp%10+'0'; } while(i2>=0) { tmp=str2[i2--]-'0'+carry; carry=tmp/10; str3[j++]=tmp%10+'0'; } if(carry) str3[j++]=carry+'0'; str3[j]='\0'; for(i=0,--j;i<j;++i,--j) { ch=str3[i]; str3[i]=str3[j]; str3[j]=ch; } } int main() { int n,c=0; char s1[205],s2[205],r[205]; scanf("%d",&n); while(n--) { if(c++) printf("\n"); s1[0]='0'; s1[1]='\0'; while(scanf("%s",s2),strcmp(s2,"0")) { Add(s1,s2,r); strcpy(s1,r); } puts(r); } return 0; }
C++ :
#include<stdio.h> #include<string.h> void Add(char *str1,char *str2,char *str3) { int i,j,i1,i2,tmp,carry; int len1=strlen(str1),len2=strlen(str2); char ch; i1=len1-1; i2=len2-1; j=carry=0; for(;i1>=0&&i2>=0;++j,--i1,--i2) { tmp=str1[i1]-'0'+str2[i2]-'0'+carry; carry=tmp/10; str3[j]=tmp%10+'0'; } while(i1>=0) { tmp=str1[i1--]-'0'+carry; carry=tmp/10; str3[j++]=tmp%10+'0'; } while(i2>=0) { tmp=str2[i2--]-'0'+carry; carry=tmp/10; str3[j++]=tmp%10+'0'; } if(carry) str3[j++]=carry+'0'; str3[j]='\0'; for(i=0,--j;i<j;++i,--j) { ch=str3[i]; str3[i]=str3[j]; str3[j]=ch; } } int main() { int n,c=0; char s1[205],s2[205],r[205]; scanf("%d",&n); while(n--) { if(c++) printf("\n"); s1[0]='0'; s1[1]='\0'; while(scanf("%s",s2),strcmp(s2,"0")) { Add(s1,s2,r); strcpy(s1,r); } puts(r); } return 0; }
Pascal :
type data=array[0..10000] of integer; var a,b,c:data; stb:string; i,j,n,lenb:longint; function gaojia(a,b:data):data; var i,j,len:integer; c:data; begin fillchar(c,sizeof(c),0); if a[0]>b[0] then len:=a[0] else len:=b[0]; for i:=1 to len do begin c[i]:=c[i]+a[i]+b[i]; c[i+1]:=c[i+1]+c[i] div 10; c[i]:= c[i] mod 10; end; if c[len+1]>0 then c[0]:=len+1 else c[0]:=len; gaojia:=c; end; begin readln(n); for i:=1 to n do begin fillchar(a,sizeof(a),0); a[0]:=1;a[1]:=0; readln(stb); while stb<>'0' do begin lenb:=length(stb); b[0]:=lenb; for j:=1 to lenb do val(stb[j],b[lenb-j+1]); c:=gaojia(a,b); a:=c; readln(stb); end; for j:=c[0] downto 1 do write(c[j]); writeln; writeln; end; end.
Java :
import java.math.BigInteger; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner cin=new Scanner(System.in); while(cin.hasNext()) { int n=cin.nextInt(); while(n--!=0) { BigInteger b2=BigInteger.ZERO; BigInteger b1; while(true) { b1=cin.nextBigInteger(); if(b1.compareTo(BigInteger.ZERO)==0) { break; } b2=b2.add(b1); } System.out.print(b2); if(n>0) System.out.println("\n"); b1=BigInteger.ZERO; } } } }
Python :
first = True for t in xrange(input()): ans = 0 while True: x = input() ans += x if x == 0: if not first: print '' first = False print ans break
- 1
信息
- ID
- 6267
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者