c语言全wa求调
  • 板块B2122 单词翻转
  • 楼主cZanY
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/12/31 09:37
  • 上次更新2024/12/31 19:20:51
查看原帖
c语言全wa求调
1544174
cZanY楼主2024/12/31 09:37

自己试的一些样例输出都是正确的,为什么提交上去就全wa了

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    char str[100];
    fgets(str, 100, stdin);

    str[strcspn(str,"\n")] = '\0';

    char *word = strtok(str," ");

    while (word != NULL) {
        int len = strlen(word);
        char *new = (char*)malloc((len+1) * sizeof(char));
        if (new != NULL) {
            for (int i = 0; i < len; i++) {
                new[i] = word[len - 1- i];
            }
            new[len] = '\0';
            printf("%s\n",new);

            free(new);
            word = strtok(NULL," ");
        }
    }
    return 0;
}```
2024/12/31 09:37
加载中...