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

Автор SeniorBOTx, 2 года назад, По-английски

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 ^ _ *

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

haha cout<< makes BOOM