HDU2564 词组缩写

2019-06-03

15:00:38

感觉有有种被坑了的感觉,这道题不难,就是一再的W,?

 

else if (a[0] >= 'A' && a[0] <= 'Z')
              {
                   cout << a[0];
              }
样例可能第一个为空格
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int t;
 6     while (cin >> t)
 7     {
 8         getchar();
 9         while (t--)
10         {
11             string a;
12             getline(cin, a);
13             
14             int lenth = a.length();
15             if (a[0] >= 'a' && a[0] <= 'z')
16             {
17                 printf("%c", a[0] - 32);
18             }
19             else if (a[0] >= 'A' && a[0] <= 'Z')
20             {
21                 cout << a[0];
22             }
23 
24             for (int i = 1; i < lenth; i++)
25             {
26                 if (a[i - 1] == ' ' && a[i] >= 'a' && a[i] <= 'z')
27                 {
28                     printf("%c", a[i] - 32);
29                 }
30                 if (a[i - 1] == ' ' && a[i] >= 'A' && a[i] <= 'Z')
31                 {
32                     printf("%c", a[i]);
33                 }
34             }
35             cout << endl;
36         }
37     }
38     return 0;
39 }
可以运用另一种方法
 
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    while(~scanf("%d", &t))
    {
        getchar();
        while(t--)
        {
            char a[100];
            gets(a);
            strupr(a);
            if(a[0] >= 'A' && a[0] <='Z')
            {
                cout << a[0];
            }
            for(int i = 1; a[i] != '\0'; i++)
            {
                if(a[i - 1] == ' ' && a[i] >= 'A' && a[i] <= 'Z')
                {
                    cout << a[i];
                }
            }
            cout << endl;
        }
    }
    return 0;
}

 

 
 
 
 

转载于:https://www.cnblogs.com/Artimis-fightting/p/10967671.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值