Cod sursa(job #717029)

Utilizator w3.playerCostescu Ionut w3.player Data 19 martie 2012 15:58:23
Problema Tribute Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream.h>
#include <iostream.h>
#include <math.h>
int main()
{
	int n,x,y,i,j,k,z,t,qx,qy,s=0;
	ifstream f("tribute.in");
	f >> n >> x >> y;
	for (i=0; i<n; i++)
	{
		f >> z >> t;
		qx=0; qy=0;
		for (j=0; j<=x; j++)
		{
			if (j==z)
				qx=1;
			for (k=0; k<=y; k++)
				if (k==t)
					qy=1;
		}
		if (qx!=1 && qy!=1)
			s=s+abs(x-z)+abs(y-t);
		if (qx==1 && qy!=1)
			s+=abs(y-t);
		if (qx!=1 && qy==1)
			s+=abs(x-z);
	}
	f.close();
	ofstream g("tribute.out");
	g << s << "\n";
	g.close();
	return 0;
}