标签:
5 1 2 3 4 1
2 2 3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn = 10010; 6 int a[maxn],pos[maxn],n; 7 int main() { 8 while(~scanf("%d",&n)) { 9 memset(pos,-1,sizeof pos); 10 bool flag = true; 11 int sum = pos[0] = 0; 12 for(int i = 1; i <= n; ++i) { 13 scanf("%d",a + i); 14 sum = (sum + a[i])%n; 15 if(pos[sum] > -1 && flag) { 16 printf("%d\n", i - pos[sum]); 17 for(int j = pos[sum] + 1; j <= i; ++j) 18 printf("%d\n",a[j]); 19 flag = false; 20 } 21 pos[sum] = i; 22 } 23 } 24 return 0; 25 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4850893.html