Advertisement
CooBin

template_codeC++

Oct 22nd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. // ~~~ From Coo@King with love and peace ~~~
  2. #include<bits/stdc++.h>
  3. #define FILE "sample"
  4. using namespace std;
  5.  
  6. namespace FastIO
  7. {
  8.     template<class T > inline bool read(T &x) // signed int and long long
  9.     {
  10.         char c; bool flag = 0;
  11.         do { c = getchar(); } while (!isdigit(c) && c != '-' && c != EOF);
  12.         if (c == EOF) return 0;
  13.         if (c == '-') flag = 1, c = getchar();
  14.         x = c - '0';
  15.         do
  16.         {
  17.             c = getchar();
  18.             if (c == EOF || !isdigit(c)) break;
  19.             x = x * 10 + c - '0';
  20.         }
  21.         while (1);
  22.         if (flag) x = -x;
  23.         return 1;
  24.     }
  25.  
  26.     inline bool read(string &x) // normal string with [0..9], [a..z], [A..Z]
  27.     {
  28.         char c;
  29.         do { c = getchar(); } while (!isalnum(c) && c != EOF);
  30.         if (c == EOF) return 0;
  31.         x.clear(); x += c;
  32.         do
  33.         {
  34.             c = getchar();
  35.             if (c == EOF || !isalnum(c)) break;
  36.             x += c;
  37.         }
  38.         while (1);
  39.         return 1;
  40.     }    
  41.  
  42.     template<class T > inline void write(T x)
  43.     {
  44.         if (x < 0) putchar('-'), write(-x);
  45.         else
  46.         if (x < 10) putchar(x + '0');
  47.         else write(x / 10), putchar(x % 10 + '0');
  48.     }
  49.  
  50.     inline void write(string &x)
  51.     {
  52.         for (char c : x) putchar(c);
  53.     }
  54. }
  55.  
  56.  
  57.  
  58. main()
  59. {
  60.     if (fopen("main.in", "r"))
  61.         // assert(freopen("main.out", "w", stdout)),
  62.         // assert(freopen("main.err", "w", stderr)),
  63.         assert(freopen("main.in", "r", stdin));
  64.     else
  65.         // assert(freopen(FILE".out", "w", stdout)),
  66.         assert(freopen(FILE".inp", "r", stdin));
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement