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

Discussion of Problem 1307. Archiver

Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by tiancaihb 8 Aug 2010 18:38
On my dev-c++ (gcc) and on the old Timus compiler, they accept such code:
char a[]="xxx...xxx";  (there are up to 200000 'x')
But after lots of WA1's I tried to run it on VC2008, it won't compile!
It said that sth like "string is to long" (Sorry my VC isn't in English so I can't tell exactly)
So to solve this problem now, you have to think of a more complicated way...

And it took me much effort to escape that terrible WA1..
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by Evgeniy++ 8 Aug 2010 18:56
Exactly!

In MSVC2008 we have the following restrictions on strings in C++:

Length of one string unit must not be more than 65535 symbols (with ending \0 it is 65536).

If you have greater string, you must devide it into several sub-strings, like I did in my solution:

const char* psz[] = { "string one", "string two", ... };

And you cant write in one line more than ~2000 charecters in your source file, you have to put newline after each 2000 chars chunk, or compilation error will occure.
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by tiancaihb 8 Aug 2010 19:30
Yeah, thx, but eventually I split it into array of char[1000] and it's all right to write the whole array on a single line.
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by Sergey Lazarev (MSU Tashkent) 9 Aug 2010 21:50
I think you are wrong.
I've submitted my old solution, which has "unsigned char s[]="..." written in one line, and got AC again.
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by Evgeniy++ 9 Aug 2010 22:21
The only thing I have is my own experience with MS C++ 2008 compiler. Maybe in VS C++ 2010 (which is currently used on Timus) they took off that restriction.
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by Fly [Yaroslavl_SU] 3 Nov 2010 07:30
* Be careful with percent signs using printf function:
  printf( "...if(c%3==0)..." ); // wrong!!! but sometimes it works
  printf( "...if(c%%3==0)..." ); // right

* It isn't necessary but if you don't want to take care about CR LF characters, you can use this code:
  #include <io.h>
  #include <fcntl.h>
  _setmode(_fileno(stdin),_O_BINARY);
  _setmode(_fileno(stdout),_O_BINARY);

* Don't use these characters: " ? \

Edited by author 03.11.2010 07:54
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by [York Hotel] 3xian 30 Dec 2010 20:42
Exactly.
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by Vit Demidenko 29 Jun 2011 18:52
in vc on timus limit ~16000 symbols

Edited by author 29.06.2011 18:52
Re: Hint for C/C++: Be careful of the NEW COMPILER!!
Posted by tyomitch 24 Jan 2013 22:41
Another gotcha for C++ programmers:

The line terminator in the input is "\r\n", so if you read input byte-by-byte, you will see both chars, but if you try to output "\r\n" via std::cout, you will get "\r\r\n" in the output.

My solution was to just ignore \r in the input.