hdu——2564——词组缩写

来源:互联网 发布:数组是线性表吗 编辑:程序博客网 时间:2024/06/01 10:40
Problem Description
定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写。
比如,C语言里常用的EOF就是end of file的缩写。

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

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

Sample Input
1
end of file 
 
Sample Output
EOF
 
#include <iostream>#include <cstring>#include <cstdio>#include <string.h>#include <cstdlib>#include <algorithm>using namespace std;char fun(char c){if(c>='a'&&c<='z')return c-32;else if(c>='A'&&c<='Z')return c;}int main(){int t;scanf("%d",&t);getchar();char s[300];while(t--){memset(s,'0',sizeof(s));gets(s);int i;int t;        for(i=0;i<strlen(s);i++)        {        if(isalpha(s[i]))        {        t=i;        break;        }        }    cout<<fun(s[t]);    for(int j=t;j<strlen(s)+1;j++)    {    if(s[j]==' '&&isalpha(s[j+1]))    cout<<fun(s[j+1]);    }cout<<endl;}return 0;}

测试样例:

6

end of file
EOF
  end of file
EOF
e c v bnm
ECVB
  e c v bnm
ECVB
0 0