SeniorBOTx's blog

By SeniorBOTx, 6 weeks ago, In English

We know that we waste lot of time to print or cout things in C++.

Suppose you have to print 1, 2, 3, 4.

cout << 1 << " " << 2 << " " << 3 << " " << 4 << endl;

Or print pair in vector . It take lot of time . I know if you are typing speed is 80+ then what ? You still wasting time ? So I decide to make print function same as python to Overcome this.

void Print(int32_t x) {cout << x << " ";} void Print(char x) {cout << x << " ";} void Print(const char *x) {cout << x << " ";} void Print(double x) {cout << x << " ";} void Print(int x) {cout << x << " ";} void print() {cout << endl;}
void Print(bool x) {cout << (x ? "YES" : "NO");} void Print(const string &x) {cout << x << " ";}  template<typename T, typename V> void Print(const pair<T, V> x) {cout << x.F << " " << x.S << endl;}
template<typename T> void Print(const T &x) {for (auto &i : x) Print(i);} template <typename T, typename... V> void print(T t, V... v) { Print(t); print(v...);}


cout << 1 << " " << 2 << " " << 3 << " " << 4 << endl;
print(1,2,3,4); //will do the same effect.

vector<int> v;
for(auto x:v) cout << x << " "; cout << endl;  // 1 2 3 4...
print(v)  // same effect as above

set<int> s;
for(auto x:s) cout << x << " "; cout << endl;  // 1 2 3 4 5 6.... 
print(s);

pair<int,int> z = { 1, 3};
cout << z.first << " " << z.second << endl;   // 1 3
print(z);  // 1 3

string s1,s2,s3;
cout << s1 << " " << s2 << " " << s3 << endl;
print(s1,s2,s3);

bool flag = true;
if (flag) cout << "YES" << endl;
else cout << "NO" << endl;

print(flag) // same effect as above

// Even you can put any condition here .
print(1 > 0);  // YES
print(n&1);    // if n is odd output is YES otherwise NO


hope this will save time , happy cp ^ _ *

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

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

In particular this is basically for codeforces

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

One way I think this can be improved on is by making the print function work similar to in python with something like an end= parameter. The default should be '\n', but when you are printing something like a vector for example you can pass in [space, ' '] so the end of the print will be a space instead of a new line.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

haha cout<< makes BOOM