chrs's blog

By chrs, history, 8 years ago, In English

Hi Friends,

Anyone know if there is a plugin somewhere for C++ so I dont have to write all the boiler plate iostream code? Or is writing Cin apart of the contest?

Ty :3

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

| Write comment?
»
8 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Looking at your code, I think the main issue is just that you're doing input in a weird way. Usually, people just use cin for everything.

For example, look at one of my solution's inputs compared to yours.

Mine: http://codeforces.me/contest/1011/submission/40786335

Yours: http://codeforces.me/contest/1011/submission/40792933

You kinda write input like you're using Python.

  • »
    »
    8 years ago, hide # ^ |
    ← Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Thanks for the reply Chili.

    I write in that style too (Using CIN). But sometimes when the input is too large, CIN doesnt work, and I have to use getline().

    In today's contest, I think I spent over 50% of time getting my IO to work. It was the most frustrating thing ever. Hopefully I can speed it up next time... Sigh...

    • »
      »
      »
      8 years ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I've almost never had issues with cin being too slow, assuming you have sync_with_stdio stuff. The only times I ever need get_line are when I seriously need the entire line, and not just one word/number.

      Could you give an example of a problem where you had issues just directly using cin?

    • »
      »
      »
      8 years ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      Always add this at the beginning of main:

      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      

      I personally use this when competing. This makes I/O a lot faster.

      • »
        »
        »
        »
        8 years ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I will. Any reasons why?

        Thanks Ivan.

        • »
          »
          »
          »
          »
          8 years ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          It was kind of hard for me to figure out what was going wrong with your submission before, but I doubt it was related to cin; you don't usually get runtime errors from stuff like that.

          As for why you should use the things above, cin/cout by default synchronize their buffers with scanf/printf. This makes them a lot slower. The first one is the most important, the second is often just tossed in there, and I don't actually use the third line.