转自 bdd :http://www.cnblogs.com/kevince/p/3924688.html
读入优化:
1 inline int read() 2 { 3 char ch; 4 bool flag = false; 5 int a = 0; 6 while(!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-'))); 7 if(ch != '-') 8 { 9 a *= 10; 10 a += ch - '0'; 11 } 12 else 13 { 14 flag = true; 15 } 16 while(((ch = getchar()) >= '0') && (ch <= '9')) 17 { 18 a *= 10; 19 a += ch - '0'; 20 } 21 if(flag) 22 { 23 a = -a; 24 } 25 return a; 26 }
输出优化:
1 void write(int a) 2 { 3 if(a < 0) 4 { 5 putchar('-'); 6 a = -a; 7 } 8 if(a >= 10) 9 { 10 write(a / 10); 11 } 12 putchar(a % 10 + '0'); 13 putchar(' '); 14 }