Pagini recente » Cod sursa (job #1920233) | Cod sursa (job #3174842) | Cod sursa (job #2624149) | Cod sursa (job #686277) | Cod sursa (job #26052)
Cod sursa(job #26052)
#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[51][501], i, j, e2[51][501], aux, n, u, t;
int vec1[501], vec2[501], vecfin1[501], vecfin2[501];
int aux1, aux2;
bool stop;
vec1[0]=-1; vec2[0]=-1;
while (!f1.eof())
{
f1>>n>>t>>u;
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;
}