7-115 词组缩写
分数 100
全屏浏览
定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写。
比如,C语言里常用的 EOF 就是 end of file 的缩写。
输入格式:
测试数据占一行,有一个词组(总长度不超过 200),每个词组由一个或多个单词组成;每组的单词个数不超过 10 个,每个单词有一个或多个大写或小写字母组成;
单词长度不超过 10,由一个或多个空格分隔这些单词。
输出格式:
输出规定的缩写。
输入样例:
end of file
输出样例:
EOF
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
#include<stdio.h>
#include<string.h>
int main()
{
char str[200];
gets(str);
int len=strlen(str);
for(int i=0;i<len;i++)
{
if(i==0)
{
if(str[i]>='A' && str[i]<='Z')
{
printf("%c",str[i]);
}
else{
printf("%c",str[i]-32);}
}
else if(str[i]==' ' && str[i+1]!=' ')
{
if(str[i+1]>='A' && str[i+1]<='Z')
{
printf("%c",str[i+1]);
}
else
{
printf("%c",str[i+1]-32);
}
}
}
return 0;
}