用c语言编程:给出了一串大写和小写的英文字母和空格。在行的末尾点符号为。从字符串中删除每个单词的首字母。输入格式由大写和小写英文字母以及不超过 1000 个字符的空格组成的字符串。输出格式一串大写和小写英文字母和空格例子输入Hello world输出ello orld
#include <stdio.h> #include <string.h>
int main() { char str[1001]; fgets(str, 1001, stdin); // 读入字符串
int len = strlen(str);
for (int i = 0; i < len; i++)
{
if (str[i] == ' ') // 如果当前字符是空格,说明前面是一个单词
{
i++; // 跳过空格,指向单词的第二个字符
while (str[i] != ' ' && str[i] != '.') // 删除单词首字母,直到遇到空格或句号
{
printf("%c", str[i]);
i++;
}
}
printf("%c", str[i]); // 输出当前字符
}
return 0;
原文地址: http://www.cveoy.top/t/topic/heCQ 著作权归作者所有。请勿转载和采集!