Pagini recente » Borderou de evaluare (job #1652075) | Cod sursa (job #1616934) | Cod sursa (job #3153564) | Borderou de evaluare (job #815037) | Cod sursa (job #1395291)
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
ifstream fin ("congr.in");
ofstream fout ("congr.out");
int P, s,a[1000000];
int main()
{
int i,x1,x2;
srand(time(NULL));
fin >> P;
for(i=1; i<2*P; i++)
{
fin >> a[i];
if(i<=P)
s+=a[i];
}
if(s%P==0) for(i=1; i<=P; i++) fout << a[i] << ' ';
else
while(s%P!=0)
{
x1=rand()%P;
x2=rand()%P+P-1;
swap(a[x1],a[x2]);
if((s-a[x1]+a[x2])%P==0)
{
fout << a[i] << ' ';
}
}
return 0;
}