Pagini recente » Cod sursa (job #2285858) | Cod sursa (job #2359228) | Cod sursa (job #1916837) | Cod sursa (job #1913146) | 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;
}