题解 | 句子逆序
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000] = {0};
fgets(s, 1000, stdin);
int len = strlen(s);
s[strcspn(s, "\n")] = '\0';
char* end = s + len;
char t[1000][1000] = {0};
char* p = NULL;
int count = 0;
int curLen = 0;
while((p = strrchr(s, ' ')) != NULL)
{
memcpy(t[count], p+1, end - p);
t[count][strcspn(t[count], "\n")] = ' ';
memset(p, '\0', end - p);
++count;
}
memcpy(t[count], s, strlen(s));
++count;
for(int loop = 0; loop < count; ++loop)
{
printf("%s", t[loop]);
}
return 0;
}
查看27道真题和解析