//土尔逊Torson 编写于2023/4/20 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <stdlib.h> using namespace std; bool isSpliter(char c) {//在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\0') { return true; } else { return false; } } int main() { //双指针步进即可,用string再split太慢了 //scanf会吃掉空格,用getline string words; while (getline(cin, words)) { words = words + '\0'; //末尾加结束符,因为循环时会跳过结尾处,处理字符串要注意边界问题。 int i = 0, j = 0; while (words[j] != '\0' && words[i] != '\0') { while (!isSpliter(words[j])) j++; if ('a' <= words[i] && words[i] <= 'z') words[i] -= 32; i = ++j; } words = words.substr(0, words.size() - 1); //恢复原始大小 printf("%s\n", words.c_str()); } //system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")