Advertisement
Mlxa

### Быстрый и удобный ввод

Feb 13th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define long ll
  5. #define all(x) begin(x), end(x)
  6.  
  7. namespace fastio {
  8. template<class T>
  9. T read() {
  10.     assert(false);
  11. }
  12.  
  13. template<class T>
  14. void print(T var) {
  15.     assert(false);
  16. }
  17.  
  18. const int BUF = 1 << 12;
  19. char read_buf[BUF];
  20. char write_buf[BUF];
  21. int read_pos = 0;
  22. int read_len = 0;
  23. int write_pos = 0;
  24.  
  25. struct Flusher {
  26.     ~Flusher() {
  27.         fwrite(write_buf, 1, write_pos, stdout);
  28.     }
  29. } flusher;
  30.  
  31. bool is_eof() {
  32.     if (read_pos == read_len) {
  33.         read_len = (int)fread(read_buf, 1, BUF, stdin);
  34.         read_pos = 0;
  35.     }
  36.     if (read_pos == read_len) {
  37.         return true;
  38.     }
  39.     return false;
  40. }
  41.  
  42. char get_char() {
  43.     if (is_eof()) {
  44.         return -1;
  45.     }
  46.     return read_buf[read_pos++];
  47. }
  48.  
  49. template<>
  50. char read<char>() {
  51.     char c = get_char();
  52.     while (c <= ' ') {
  53.         c = get_char();
  54.     }
  55.     return c;
  56. }
  57.  
  58. template<>
  59. void print(char x) {
  60.     if (write_pos == BUF) {
  61.         fwrite(write_buf, 1, write_pos, stdout);
  62.         write_pos = 0;
  63.     }
  64.     write_buf[write_pos++] = x;
  65. }
  66.  
  67. template<>
  68. int read<int>() {
  69.     int sum = 0;
  70.     char c = read<char>();
  71.     int sign = +1;
  72.     if (c == '-') {
  73.         sign = -1;
  74.         c = get_char();
  75.     }
  76.     while ('0' <= c && c <= '9') {
  77.         sum = 10 * sum + c - '0';
  78.         c = get_char();
  79.     }
  80.     return sum * sign;
  81. }
  82.  
  83. template<>
  84. ll read<ll>() {
  85.     ll sum = 0;
  86.     char c = read<char>();
  87.     int sign = +1;
  88.     if (c == '-') {
  89.         sign = -1;
  90.         c = get_char();
  91.     }
  92.     while ('0' <= c && c <= '9') {
  93.         sum = 10 * sum + c - '0';
  94.         c = get_char();
  95.     }
  96.     return sum * sign;
  97. }
  98.  
  99. template<>
  100. void print(int x) {
  101.     static char s[30];
  102.     int n = 0;
  103.     if (x < 0) {
  104.         print('-');
  105.         x = -x;
  106.     }
  107.     while (!n || x) {
  108.         s[n++] = (char)(x % 10 + '0');
  109.         x /= 10;
  110.     }
  111.     while (--n >= 0) {
  112.         print(s[n]);
  113.     }
  114. }
  115.  
  116. template<>
  117. void print(ll x) {
  118.     static char s[30];
  119.     int n = 0;
  120.     if (x < 0) {
  121.         print('-');
  122.         x = -x;
  123.     }
  124.     while (!n || x) {
  125.         s[n++] = (char)(x % 10 + '0');
  126.         x /= 10;
  127.     }
  128.     while (--n >= 0) {
  129.         print(s[n]);
  130.     }
  131. }
  132. }
  133. using namespace fastio;
  134.  
  135. int main() {
  136. #ifdef LC
  137.     assert(freopen("input.txt", "r", stdin));
  138. #endif
  139.     ios::sync_with_stdio(false);
  140.     cin.tie(nullptr);
  141.    
  142.     int a = read<int>();
  143.     int b = read<int>();
  144.    
  145.     print(a + b);
  146.     print('\n');
  147.    
  148.     return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement