读入优化

无负数:

1 inline int nextInt() {  
2     char c;  
3     while (c = getchar(), c < '0' || c > '9');  
4     int r = c - '0';  
5     while (c = getchar(), c >= '0' && c <= '9') r = r * 10 + c - '0';  
6     return r;  
7 }  

有负数:

1 void scanf ( int& x , char c = 0 , int flag = 0 ) {
2     while ( ( c = getchar () ) != '-' && ( c < '0' || c > '9' ) ) ;
3     if ( c == '-' ) flag = 1 , x = 0 ;
4     else x = c - '0' ;
5     while ( ( c = getchar () ) >= '0' && c <= '9' ) x = x * 10 + c - '0' ;
6     if ( flag ) x = -x ;
7 }

 

posted on 2015-01-07 17:04  xiao_xin  阅读(94)  评论(0编辑  收藏  举报

导航