IvanSimic's blog

By IvanSimic, history, 3 months ago, In English

Hello Codeforcers,

When I switched from Python to C++, I got a problem while inputting. I was stuck with it for 10 days until I realised how easy it is. I just want to write it here for others if they also get stuck here.

In competitive programming, inputting more variables in one line is quite common.

In Python, if you want to enter two variables in a single line, you have to do this:

a, b = input().split()

While in c++, you can simply use 2 cins like your inputting in 2 lines. The way you do it (in line, spaced) doesn't matter.

string a, b;
cin >> a;
cin >> b;

or

string a, b;
cin >> a >> b;

This way you can input a vector of size n in one line:

vector<int> v(n);

for(int i = 0; i < n; i++) {
    cin >> v[i];
}
  • Vote: I like it
  • -17
  • Vote: I do not like it

»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by IvanSimic (previous revision, new revision, compare).

»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This changes everything. History will remember this moment.

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

    I know this is basic knowledge, but this is what I got stuck on somehow and couldn't find an answer for.

»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I guess, this is why greytist came to be!