1.
int read()
{
char c = getchar();
int f = 1, x = 0;
while(!isdigit(c)) {if(c == '-') f = -1;c = getchar();}
while(isdigit(c)){x = x * 10 + c - 48;c = getchar();}
//对于“x” 还可以- x = (x << 1) + (x << 3) + (c - 48);
//"48"指 ‘0’;
return x * f;
}
isdigit() 算机C(C++)语言中的一个函数,主要用于检查其参数是否为十进制数字字符
int read()
{
char c = getchar();
int f = 1, x = 0;
while(c<'0'||c>'9') {if(c == '-') f = -1;c = getchar();}
while(c>='0'&&c<='9'){x = x * 10 + c - 48;c = getchar();}
return x * f;
}
注:要写<cstring>
头
%%%