Skip to main content

input / output

Always MUST add :~ ios_base::sync_with_stdio(false);

caution

MUST ADD 👇

    ios::sync_with_stdio(false);
// ios_base::sync_with_stdio(false); // used by "ksun48" & "ecnerwala"

MUST Add :~ cin.tie(NULL);

caution
    cin.tie(nullptr);   // used by ""ksun48" "2021 CodeJam Champion" & "ecnerwala"
// cin.tie(NULL);
// cin.tie(0); // used by "TOURIST" & "maroonrk"


Using scanf & printf

// #include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <climits>
#include <algorithm>
// #include <array>
//#include <string>

using namespace std;

int main()
{
//FASTER THAN cout and cin
//printf and scanf from C
int n, key;
scanf("%d %d", &n, &key);

printf("%d %d %d\n%d %d", n, key, key, key, n); //the way "%d %d" is written determines the way Output is printed
//the the no. of times "%d" is equal to the no.s of variables

//cin and cout from C++
int a, keys;
cin >> a >> keys;

cout << a << " " << keys << "\n"; //"\n" should be used instead of endl

string str;
getline(cin, str); //to take a whole line as input "getline(sin, variable_name) is used"

return 0;
}

OPTIONAL

flush

caution

Try to flush as little as possible.

But always flush where necessary.

cout << flush;

OR

cout.flush();

OR

cout << endl;