Contents
  • 这个是针对于纯数字的输入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

输入外挂
int readint()
{

int res = 0, ch, flag = 0;

if((ch = getchar()) == '-') //判断正负
flag = 1;

else if(ch >= '0' && ch <= '9') //得到完整的数
res = ch - '0';
while((ch = getchar()) >= '0' && ch <= '9' )
res = res * 10 + ch - '0';

return flag ? -res : res;
}


输出外挂

int buf[100]; //声明成全局变量可以减小开销
void writeint(int i) {
int p = 0;
if(i == 0)
p++; //特殊情况:i等于0的时候需要输出0,而不是什么也不输出
else
while(i){
buf[p++] = i % 10;
i /= 10;
}
for(int j = p-1; j >=0; j--)
putchar('0' + buf[j]); //逆序输出
}
Contents