ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

I don't know C++. See program. i want thet my program didn't read from file
Posted by I am david. Tabo. 26 Nov 2002 22:29
#include <fstream.h>
#include <search.h>

ifstream in("input.txt");
ofstream out("output.txt");

const maxn=15000;

struct TStar
{
  int x, y;
  int operator < (const TStar &s) const { return x<s.x || (x==s.x &&
y<s.y); }
  void input() { in>>x>>y; }
};

TStar stars[maxn];
int far counts[maxn]={0};
int far stats[maxn]={0};

int sortf( const void *a, const void *b)
{
  const TStar &sa=*(const TStar *)a;
  const TStar &sb=*(const TStar *)b;
  return sa<sb ? -1 : sb<sa ? 1 : 0;
}

int main()
{
  int n; in>>n;
  for(int i=0;i<n;i++) stars[i].input();
  qsort((void *)stars, n, sizeof(stars[0]), sortf);
  in.close();
  in.open("input.txt");
  in>>n;
  for(i=0;i<n;i++)
  {
    TStar s; s.input();
    int l=0, r=n-1, c=0;
    while(l!=r)
    {
      int o=(l+r)/2;
      if(stars[o]<s) { c+=counts[o]; l=o+1; }
      else { counts[o]++; r=o; }
    }
    stats[c]++;
  }
  for(i=0;i<n;i++)
    out<<stats[i]<<endl;
  return 0;
}