HDU 6044

fast IO

考虑边界情况

 1 namespace IO {
 2     const int MT = 40 * 1024 * 1024;  /// 40MB 请注意输入数据的大小!!!
 3     char IO_BUF[MT];
 4     int IO_PTR, IO_SZ;
 5     /// 要记得把这一行添加到main函数第一行!!!
 6     void begin() {
 7         IO_PTR = 0;
 8         IO_SZ = fread (IO_BUF, 1, MT, stdin);
 9     }
10     template<typename T>
11     inline bool scan_d (T & t) {
12         while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != '-' && (IO_BUF[IO_PTR] < '0' || IO_BUF[IO_PTR] > '9'))
13             IO_PTR ++;
14         if (IO_PTR >= IO_SZ) return false;
15         bool sgn = false;
16         if (IO_BUF[IO_PTR] == '-') sgn = true, IO_PTR ++;
17         for (t = 0; IO_PTR < IO_SZ && '0' <= IO_BUF[IO_PTR] && IO_BUF[IO_PTR] <= '9'; IO_PTR ++)
18             t = t * 10 + IO_BUF[IO_PTR] - '0';
19         if (sgn) t = -t;
20         return true;
21     }
22     inline bool scan_s (char s[]) {
23         while (IO_PTR < IO_SZ && (IO_BUF[IO_PTR] == ' ' || IO_BUF[IO_PTR] == '
') ) IO_PTR ++;
24         if (IO_PTR >= IO_SZ) return false;
25         int len = 0;
26         while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != ' ' && IO_BUF[IO_PTR] != '
')
27             s[len ++] = IO_BUF[IO_PTR], IO_PTR ++;
28         s[len] = '';
29         return true;
30     }
31     template<typename T>
32     void print(T x) {
33         static char s[33], *s1; s1 = s;
34         if (!x) *s1++ = '0';
35         if (x < 0) putchar('-'), x = -x;
36         while(x) *s1++ = (x % 10 + '0'), x /= 10;
37         while(s1-- != s) putchar(*s1);
38     }
39     template<typename T>
40     void println(T x) {
41         print(x); putchar('
');
42     }
43 };
View Code
原文地址:https://www.cnblogs.com/skyette/p/7599811.html