题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include<stdio.h>
#include<string.h>
#define SIZE 1000
int main()
{
int i = 0, j = 0,k = 0;
char ch;
char a[SIZE][SIZE];
//把输入存在二位数组里
while((ch = getchar()) != '\n'){
if(ch != ' '){
a[i][j] = ch;
j++;
}
else{
j = 0;
i++;
}
}
//遍历数组输出
for(k = i;k >= 0;k--){
printf("%s",a[k]);
printf(" ");
}
return 0;
}
#include<string.h>
#define SIZE 1000
int main()
{
int i = 0, j = 0,k = 0;
char ch;
char a[SIZE][SIZE];
//把输入存在二位数组里
while((ch = getchar()) != '\n'){
if(ch != ' '){
a[i][j] = ch;
j++;
}
else{
j = 0;
i++;
}
}
//遍历数组输出
for(k = i;k >= 0;k--){
printf("%s",a[k]);
printf(" ");
}
return 0;
}