Pagini recente » Cod sursa (job #1720305) | Cod sursa (job #2299279) | Cod sursa (job #490857) | Cod sursa (job #2294166) | Cod sursa (job #26056)
Cod sursa(job #26056)
#include <fstream>
#include <iostream>
using namespace std;
ifstream f1("amlei.in");
ofstream f2("amlei.out");
int abs(int a)
{
if (a<0) return -a;
if (a>=0) return a;
}
int pow(int a, int b)
{
int aux, i;
aux=1;
for (i=1; i<=b; i++)
{
aux*=aux;
}
return aux;
}
int main(void)
{
int e1[100][1000], i, j, e2[100][1000], aux, n, u, t;
int vec1[1000], vec2[1000], vecfin1[1000], vecfin2[1000];
int aux1, aux2;
bool stop;
while (!f1.eof())
{
f1>>n>>t>>u;
vec1[0]=-1; vec2[0]=-1;
for (i=1; i<=t; i++)
{
for (j=1; j<=n; j++)
{
f1>>aux;
e1[i][abs(aux)]=(aux/abs(aux)+1)/2;
}
}
for (i=1; i<=u; i++)
{
for (j=1; j<=n; j++)
{
f1>>aux;
e2[i][abs(aux)]=(aux/abs(aux)+1)/2;
}
}
for (i=1; i<=t; i++)
{
vec1[i]=0;
for (j=1; j<=n; j++)
vec1[i]+=e1[i][j]*pow(2,n-j);
}
for (i=1; i<=u; i++)
{
vec2[i]=0;
for (j=1; j<=n; j++)
vec2[i]+=e2[i][j]*pow(2,n-j);
}
stop=false;
while(!stop)
{
stop=true;
for (i=1; i<=t-1; i++)
if (vec1[i]>vec1[i+1])
{
stop=false;
aux=vec1[i];
vec1[i]=vec1[i+1];
vec1[i+1]=aux;
}
}
stop=false;
while(!stop)
{
stop=true;
for (i=1; i<=u-1; i++)
if (vec2[i]>vec2[i+1])
{
stop=false;
aux=vec2[i];
vec2[i]=vec2[i+1];
vec2[i+1]=aux;
}
}
aux1=0;
for (i=1; i<=t; i++)
if (vec1[i]!=vec1[i-1])
{
aux1+=1;
vecfin1[aux1]=vec1[i];
}
aux2=0;
for (i=1; i<=u; i++)
if (vec2[i]!=vec2[i-1])
{
aux2+=1;
vecfin2[aux2]=vec2[i];
}
/*
for (i=1; i<=t; i++)
f2<<vecfin1[i]<<" ";
f2<<endl;
for (i=1; i<=u; i++)
f2<<vecfin2[i]<<" ";
f2<<endl<<endl<<endl;*/
if (aux1!=aux2) f2<<"NU"<<endl;
else
{
stop=true;
for (i=1; i<=aux; i++)
if (vecfin1[i]!=vecfin2[i])
{
f2<<"NU"<<endl;
stop=false;
break;
}
if (stop) f2<<"DA"<<endl;
}
}
return 0;
}