Cod sursa(job #25572)

Utilizator bacerandreiBacer Andrei bacerandrei Data 4 martie 2007 12:59:17
Problema Puteri Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 3, Clasa a 9-a si gimnaziu Marime 0.83 kb
#include<fstream.h>
long a[100000],b[100000],c[100000],n,i,d,e,h,p,j,nr;
int max(int x,int y,int z)
{
 int max=0;
  if(x>max)
   max=x;
  if(y>max)
   max=y;
  if(z>max)
   max=z;
  return max;
}
int main()
{
  ifstream f("puteri.in");
  ofstream g("puteri.out");
   f>>n;
  for(i=1;i<=n;i++)
    f>>a[i]>>b[i]>>c[i];
  f.close();
   i=1;
    while(i<n)
     {
      for(j=i+1;j<=n;j++)
       {
	d=a[i]+a[j];
	e=b[i]+b[j];
	h=c[i]+c[j];
	 if((d==0&&e==0)||(e==0&&h==0)||(d==0&&h==0))
	  nr++;
	 else
	 if((d==e&&h==0&&d!=1)||(d==h&&e==0&&d!=1)||(e==h&&d==0&&e!=1))
	  nr++;
	 else
	  {
	p=max(d,e,h);
	 if(d==0)
	  d=p;
	 if(e==0)
	  e=p;
	 if(h==0)
	  h=p;
	if((p%d==0&&d!=1)&&(p%e==0&&e!=1)&&(p%h==0&&h!=1))
	 nr++;
        }
       }
      i++;
     }
    g<<nr;
   g.close();
  return 0;
}