(It should be noted that the code I wrote outputs the result when there is an answer, but OJ also reads the result from the file, so at first glance, it seems that there is a result when I have not entered it, but I don't know about OJ. In fact, I directly use the poj3370 code AC, 32 MS, and O (?_ =) O) to directly paste the code.
#include<cstdio> #include<cstring> using namespace std; #define N 100002 int sum[N],pos[N],a[N]; int main() { int n,i,r,t,j; while(~scanf("%d",&n)) { memset(pos,-1,sizeof(pos)); bool flag=false; scanf("%d",&sum[0]); a[0]=sum[0]; sum[0]%=n; pos[sum[0]]=0; if(sum[0]==0) { printf("1\n%d\n",sum[0]); flag=1; } for(i=1;i<n;i++) { scanf("%d",&sum[i]); if(flag)continue; a[i]=sum[i]; sum[i]%=n; sum[i]+=sum[i-1]; sum[i]%=n; if(sum[i]==0) { printf("%d\n",i+1); for(j=0;j<=i;j++) printf("%d\n",a[j]); flag=1; continue; } if(pos[sum[i]]==-1)pos[sum[i]]=i; else { printf("%d\n",i-pos[sum[i]]); for(j=pos[sum[i]]+1;j<=i;j++) printf("%d\n",a[j]); flag=1; } } } return 0; }