Pagini recente » Cod sursa (job #2947302) | Cod sursa (job #866981) | Cod sursa (job #546444) | Cod sursa (job #830513) | Cod sursa (job #27170)
Cod sursa(job #27170)
#include <fstream>
using namespace std;
ifstream f1("amlei.in");
ofstream f2("amlei.out");
int abs2(int a)
{
if (a<=0) return (-a);
return a;
}
long long pow2(int a, int b)
{
int i, aux;
aux=1;
for (i=1; i<=b; i++)
{
aux*=a;
}
return aux;
}
int main()
{
int e1[501][51], i, j, e2[501][51], aux, n, u, t;
int vecfin1[501], vecfin2[501];
long long vec1[501], vec2[501];
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][abs2(aux)]=(aux/abs2(aux)+1)/2;
}
}
for (i=1; i<=u; i++)
{
for (j=1; j<=n; j++)
{
f1>>aux;
e2[i][abs2(aux)]=(aux/abs2(aux)+1)/2;
}
}
for (i=1; i<=t; i++)
{
vec1[i]=0;
for (j=1; j<=n; j++)
vec1[i]+=e1[i][j]*pow2(2,n-j);
}
for (i=1; i<=u; i++)
{
vec2[i]=0;
for (j=1; j<=n; j++)
vec2[i]+=e2[i][j]*pow2(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];
}
if (aux1!=aux2) f2<<"NU"<<endl;
else
{
stop=true;
for (i=1; i<=aux1; i++)
if (vecfin1[i]!=vecfin2[i])
{
f2<<"NU"<<endl;
stop=false;
break;
}
if (stop==true) f2<<"DA"<<endl;
}
}
f1.close();
f2.close();
return 0;
}