数字读入输出:
速度较scanf、printf缩短约2/3.
#include<cstdio>
#include<cstring>
#include<cctype>//isdigit
inline int readint(){
char c = getchar();
while(!isdigit(c)) c = getchar();
int x = 0;
while(isdigit(c)){
x = x * 10 + c - '0';
c = getchar();
}
return x;
}
int buf[10];
inline void writeint(int i){
int p = 0;
if(i == 0) p++;
else while(i){
buf[p++] = i % 10;
i /= 10;
}
for(int j = p - 1; j >= 0; j--) putchar('0' + buf[j]);
}
int main(){
int n, c[105] = {0};
while(n = readint()){
for(int i = 0; i < n; i++) c[readint()]++;
for(int i = 1; i <= 100; i++){
for(int j = 0; j < c[i]; j++){
writeint(i);
putchar(' ');
}
}
}
return 0;
}
单个字符读入:
char readchar(){
char ch;
for(;;){
ch = getchar();
if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) return ch;
}
}