1215-Problem H-词组缩写-入门题-字符串处理-C++实现

问题 H: 词组缩写

时间限制: 1 Sec  内存限制: 32 MB
提交: 227  解决: 80

题目描述

定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写。
比如,C语言里常用的EOF就是end of file的缩写。

输入

输入的第一行是一个整数T,表示一共有T组测试数据。
接下来有T行,每组测试数据占一行,每行有一个词组,每个词组由一个或多个单词组成;每组的单词个数不超过10个,每个单词有一个或多个大写或小写字母组成;
单词长度不超过10,由一个或多个空格分隔这些单词。

输出

请为每组测试数据输出规定的缩写,每组输出占一行。

样例输入 Copy

1
end of file

样例输出 Copy

EOF

代码

#include <iostream>
#include <string>
#include <algorithm>
//cin遇到空格和换行符就停下来,由getchar()来吸收
//输入一整行数据其实停留在输入流中,那么你需要在字符流中用适当的输入代码从里面取出来。
using namespace std;
int main(){
    int T=0;
    string s;
    scanf("%d",&T);
    getchar();
    while(T--){
        string a;
        while(cin>>a){
            if(a[0]>='a'&&a[0]<='z'){
                printf("%c",a[0]-32);
            }
            else{
                printf("%c",a[0]);
            }
            char ch=getchar();
            if(ch=='\n'){
                break;
            }
        }
       printf("\n");
    }
    return 0;
}
发布了20 篇原创文章 · 获赞 0 · 访问量 126

猜你喜欢

转载自blog.csdn.net/weixin_31789689/article/details/104710586