Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
117181 胡海峰老师 词组缩写 C++ Compile Error 0 MS 0 KB 927 2025-04-13 22:51:33

Tests(0/0):


Code:

#include <stdio.h> #include <string.h> int main() { int T; scanf("%d", &T); // 读取测试数据的组数 getchar(); // 消除换行符 while (T--) { char phrase[1000]; // 假设每行输入的长度不超过1000 gets(phrase); // 读取整行输入 int len = strlen(phrase); int i = 0; while (i < len) { // 跳过空格 while (phrase[i] == ' ' && i < len) { i++; } // 如果已经到字符串末尾,结束循环 if (i >= len) break; // 输出当前单词的首字母,并转换为大写 putchar(toupper(phrase[i])); // 跳过当前单词的其余部分 while (phrase[i] != ' ' && i < len) { i++; } } putchar('\n'); // 每组输出后换行 } return 0; }


Run Info:

Main.cc: In function 'int main()':
Main.cc:11:9: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
         gets(phrase); // 读取整行输入
         ^
In file included from Main.cc:1:0:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
Main.cc:11:9: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
         gets(phrase); // 读取整行输入
         ^
In file included from Main.cc:1:0:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
Main.cc:11:20: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
         gets(phrase); // 读取整行输入
                    ^
In file included from Main.cc:1:0:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^
Main.cc:24:38: error: 'toupper' was not declared in this scope
             putchar(toupper(phrase[i]));
                                      ^
Main.cc:6:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &T); // 读取测试数据的组数
                    ^
Main.cc:11:21: warning: ignoring return value of 'char* gets(char*)', declared with attribute warn_unused_result [-Wunused-result]
         gets(phrase); // 读取整行输入
                     ^