Advertisement
tuki2501

fastIO

Apr 1st, 2020 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. void read(int& x) {
  2.   int neg = 0; x = 0;
  3.   char t = getchar();
  4.   while ((t < 48 || t > 57) && t != '-') t = getchar();
  5.   if (t == '-') { neg = 1; t = getchar(); }
  6.   while (t >= 48 && t <= 57) {
  7.     x = (x << 3) + (x << 1) + t - 48;
  8.     t = getchar();
  9.   }
  10.   if (neg) x = -x;
  11. }
  12.  
  13. void write(int x) {
  14.   if (x == 0) { putchar('0'); return; }
  15.   if (x < 0) { putchar('-'); x = -x; }
  16.   char a[20]; a[0] = '0';
  17.   int i = 0;
  18.   while (x) {
  19.     a[i++] = x % 10 + 48;
  20.     x /= 10;
  21.   }
  22.   for (int j = i - 1; j >= 0; j--) putchar(a[j]);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement