hdu2564词组缩写 (小组赛F) 水

来源:互联网 发布:慕课网python教程下载 编辑:程序博客网 时间:2024/04/30 20:00

链接:http://hdu.hustoj.com/showproblem.php?pid=2564

词组缩写

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13752    Accepted Submission(s): 4477


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

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

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

Sample Input
1end of file
 

Sample Output
EOF

思路:简单题 如果用字符串写,需要在最后加\0

代码:方镪同学的代码,简洁,学习学习

    #include <iostream>      #include <stdio.h>      #include <cstring>            using namespace std;            int main()      {          int t;          char s[100];          cin >> t;          getchar();//把缓冲区的\n读取掉          while(t--)          {                    gets(s);              strupr(s);//把所有字母换成大写              if(s[0] != ' ')                  printf("%c", s[0]);              for(int i = 1 ; i < strlen(s) ; i++)              {                  if(s[i] != ' ' && s[i-1] == ' ')                      printf("%c", s[i]);              }              printf("\n");              //getchar();          }      }  


0 0
原创粉丝点击