Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
40+行代码,找正确代码测试数据没问题,求帮忙啊!#include<iostream> using namespace std; int a[100][102]; int len[100]; void add(int k){ int i,t; for(i=0;i<len[k-1];i++) a[k][i]=a[k-1][i]+a[k-2][i]+a[k-3][i]; for(i=0;i<len[k-1];i++) if(a[k][i]/10>0){ a[k][i+1]+=a[k][i]/10; a[k][i]%=10; } if(a[k][i]!=0) len[k]=i+1; else len[k]=i; if(len[k]==0) len[k]=1; } int main(){ int b[3],i,j; while(scanf("%d %d %d",&b[0],&b[1],&b[2])!=EOF){ memset(a,0,sizeof(a)); for(i=0;i<3;i++){ j=0; while(b[i]){ a[i][j]=b[i]%10; b[i]=b[i]/10; j++; } len[i]=j; if(len[i]==0) len[i]=1; } for(i=3;i<=99;i++) add(i); for(i=len[99]-1;i>=0;i--) printf("%d",a[99][i]); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator