Description
The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000. This numbers are not necessarily different (so it may happen that two or more of them will be equal). Your task is to choose a few of given numbers ( 1 <= few <= N ) so that the sum of chosen numbers is multiple for N (i.e. N * k = (sum of chosen numbers) for some natural number k).
Input
The first line of the input contains the single number N. Each of next N lines contains one number from the given set.
Output
In case your program decides that the target set of numbers can not be found it should print to the output the single number 0. Otherwise it should print the number of the chosen numbers in the first line followed by the chosen numbers themselves (on a separate line each) in arbitrary order.

If there are more than one set of numbers with required properties you should print to the output only one (preferably your favorite) of them.
Sample Input
5
1
2
3
4
1
Sample Output
2
2
3

a[1]—–a[5]分别为1，2，3，4，1；

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int maxn=10005;
int num[maxn];
int mod[maxn];
int N,sum,flag=0;
int start,end;
void print(int i,int j)
{
cout<<j-i+1<<endl;
while(i<=j)
printf("%d\n",num[i++]);
}
int main()
{
cin>>N;
memset(mod,-1,sizeof(mod));
for(int i=1;i<=N;++i)
scanf("%d",&num[i]);
for(int i=1;i<=N;++i)
{
sum+=num[i];
sum%=N;
if(sum==0)
{
print(1,i);flag=1;break;
}
if(mod[sum]!=-1)
{
start=sum+1;
end=i;
print(start,end);
flag=1;break;
}
mod[sum]=i;
}
if(flag==0)
cout<<0<<endl;
return 0;

}

0
Posted in ACM