词组缩写 HDU-2564

题意: t组数据,每组数据1行,每行有若干个单词,要求输出所有单词的首字母(大写输出)

思路:很简单

错误分析:没注意到第一个单词可能是前面有空格的情况。 比较坑爹一直PE

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    int t;
    cin >> t;
    getchar();
    while(t--)
    {
        char str[600];
        gets(str);
        if(isalpha(str[0]))
            printf("%c",toupper(str[0]));
        for(int i=1;i<strlen(str);i++)
        {
            if(str[i]==' ' && str[i+1]!=' ')
            {
                if(isalpha(str[i+1]))
                    printf("%c",toupper(str[i+1]));
            }
        }
        puts("");
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务