Блог пользователя IvanSimic

Автор IvanSimic, история, 3 месяца назад, По-английски

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];
}
  • Проголосовать: нравится
  • -17
  • Проголосовать: не нравится

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This changes everything. History will remember this moment.

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I guess, this is why greytist came to be!