Cod sursa(job #25184)

Utilizator y2kClaudiu Guiman y2k Data 4 martie 2007 11:17:26
Problema Ograzi Scor 30
Compilator c Status done
Runda preONI 2007, Runda 3, Clasele 11-12 Marime 1.44 kb
#include<stdio.h>
#include<string.h>
#define IN_FILE  "ograzi.in"
#define OUT_FILE "ograzi.out"
FILE *f,*g;
char s[40];
long t[50000][2];
long n,m,nr,h,w;
void prelucrare1()
{
 int i;
 s[strlen(s)-1]='\0';
 n=0; m=0; w=0; h=0;
 i=0;
 while(s[i]!=' ')
  {
  n=n*10;
  n=n+s[i]-'0';
  i++;
  }
 i++;
 while(s[i]!=' ')
  {
  m=m*10;
  m=m+s[i]-'0';
  i++;
  }
 i++;
 while(s[i]!=' ')
  {
  w=w*10;
  w=w+s[i]-'0';
  i++;
  }
 i++;
 while(s[i]!='\0')
  {
  h=h*10;
  h=h+s[i]-'0';
  i++;
  }

}
void prelucrare2(long p)
{
 int i;
 s[strlen(s)-1]='\0';
 t[p][0]=0;
 t[p][1]=0;
 i=0;
  while(s[i]!=' ')
  {
  t[p][0]=t[p][0]*10;
  t[p][0]=t[p][0]+s[i]-'0';
  i++;
  }
 i++;
 while(s[i]!='\0')
  {
  t[p][1]=t[p][1]*10;
  t[p][1]=t[p][1]+s[i]-'0';
  i++;
  }
}
void prelucrare3()
{
 long x,y,j;
 int i;
 s[strlen(s)-1]='\0';
 x=0;
 y=0;
 i=0;
  while(s[i]!=' ')
  {
  x=x*10;
  x=x+s[i]-'0';
  i++;
  }
 i++;
 while(s[i]!='\0')
  {
  y=y*10;
  y=y+s[i]-'0';
  i++;
  }
 for(j=0; j<n; j++)
  if(x>=t[j][0] && x<=(t[j][0]+w) && y>=t[j][1] && y<=(t[j][1]+h))
   nr++;
}
int main()
{
 long i;
 f=fopen(IN_FILE,"r");
 g=fopen(OUT_FILE,"w");
 fgets(s,50,f);
  prelucrare1();
 for(i=0; i<n; i++)
  {
   fgets(s,50,f);
   prelucrare2(i);
  }
  nr=0;
 for(i=0; i<m; i++)
  {
   fgets(s,50,f);
   prelucrare3();
  }
  fprintf(g,"%d",nr);
 fclose(f);
 fclose(g);
 return 0;
}