题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
C语言编写,这应该是比较简单的,使用了scanf函数的读入指定字符集的功能,只读入大小写字母,遇到非字母的就保存并继续读取,直到读到\n结束,最后倒序输出。
#include <stdio.h>
#include <stdlib.h>
int main(){
char str[100][22];
int i=0;
int x;
while(1){
x=scanf("%[a-z|A-Z]",str[i]);
if(getchar()=='\n') break;
if(x) i++;
}
for(int j=i;j>=0;j--){
printf("%s ",str[j]);
}
return 0;
}
查看16道真题和解析