difask's blog

By difask, 10 years ago, In English

Thanks Gassa for help. The working variant is such:

#define file "taskname"	
#ifdef ONLINE_JUDGE
#define in \
        //file name in task
	freopen(file".in", "r", stdin); \
	freopen(file".out", "w", stdout);
#else
#define in \
        //your file if you use files as input
	freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout); 
#endif

int main()
{
   in;
}

It will make your code for I/O shorter.

  • Vote: I like it
  • +10
  • Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +7 Vote: I do not like it

At least you can do

#ifdef ONLINE_JUDGE
#define OJ \
	freopen(file".in", "r", stdin); \
	freopen(file".out", "w", stdout);
#else
#define OJ ;
#endif
  • »
    »
    10 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Thanks!!! It's exactly what I wanted!