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 |
求助输入的时候我是每次输入两组就结束,还是用while(scanf()!=EOF)呢? #include<stdio.h> int main() { int M,N,i,a1,b1,max[501],t; long a[500],b[500],m; scanf("%d",&M); for(i=0;i<M;i++) scanf("%ld",&a[i]); scanf("%d",&N); for(i=0;i<N;i++) scanf("%ld",&b[i]); t=0; a1=M-1; b1=N-1; m=0; while(1) { if(a[a1]>b[b1]) { if(m>a[a1]||t==0) { m=a[a1]; for(i=b1-1;i>=0;i--) if(a[a1]==b[i]) break; if(i>=0) { t++; max[t]=a1; a1--; b1=i-1; } else a1--; } else a1--; } else if(a[a1]<b[b1]) { if(m>b[b1]||t==0) { m=b[b1]; for(i=a1-1;i>=0;i--) if(a[i]==b[b1]) break; if(i>=0) { t++; max[t]=i; a1=i-1; b1--; } else b1--; } else b1--; } else { if(m>a[a1]||t==0) { m=a[a1]; t++; max[t]=a1; } a1--; b1--; } if(a1==-1||b1==-1) break; } printf("%d\n",t); if(t==0) ; else { for(i=t;i>1;i--) printf("%ld ",a[max[i]]); printf("%ld\n",a[max[1]]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator