HUSTOJ 1359 A Lazy Boy 【字符串】

1359 - A Lazy Boy

Time Limit: 1s Memory Limit: 256MB

Submissions: 363 Solved: 69
Description
Wincat is favor with computer game, yesterday he played computer game until 2:00, He is so tired that he even forgot that his English teacher had arranged homework.Today, He just realized this terrible problem when wincat wake up. He is so worry about to be punished. He know that you are good at both English and programming. So he turns to your help.This homework is to fixed the alphabet in a sentence which should be upper letter but don`t and which should be lower letter but also don`t.As we all know that “I” should always be upper letter when he appears as a word. and every alphabet that appears at the first of the sentence should be upper, other should be lower.
Input
The input contains multiple test cases, each test contains a sentence in one line. We Guarantee that there the sentence will be only contains Alphabet, “ ’ ” “ . ” ” , ” and blank space. there will be blank space everywhere, you should not remove it.A test will contains at most 200 elements.
Output
A sentence in a line which contains the correct format.
Sample Input
don’t give your child too much MoNey.
Sample Output
Don’t give your child too much money.
Hint

Source

中国地质大学(武汉)第七届ACM程序设计大赛暨华中地区部属高校ACM邀请赛


训练时这题错了几次。。。原因是没认真读题。。。。╮(╯▽╰)╭


坑点:1:空格可以在任何地方,当然也可以在开头。。。(认真读题)

           2:只要I的左右两边没有字母!!!这个i就是单个单词。要大写。

           3:这题可能出现只输入逗号或其他符号的情况(就是不输入字母。。。)

          4:特殊考虑 i 出现在最后一位上的情况

         5:右单引号的as值是39


上代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;


int main()
{
    char re[205];
    while(gets(re+1))
    {

        int len=strlen(re);
        int bz=0;
        for(int i=1; i<len; i++)///先全部变小写
        {
            if(re[i]>='A'&&re[i]<='Z')
            {
                re[i]+=32;
            }
        }
        for(int i=1; i<len; i++)
        {
            if(re[i]<='z'&&re[i]>='a')
            {
                bz=i;
                break;
            }
        }
        if(bz==0)///如果未检测到字母,直接输出
        {
            printf("%s\n",re+1);
        }
        else
        {
            re[bz]-=32;///首字母大写
            for(int i=bz+1;i<len;i++)
            {
                if(re[i]=='i')
                {
                    if(i==len-1)///特殊判断当i在最后一位的情况
                    {
                        if(re[i-1]==','||re[i-1]==39||re[i-1]=='.'||re[i-1]==' ')
                        {
                            re[i]-=32;
                        }
                    }
                    else
                    {
                        if((re[i-1]==','||re[i-1]==39||re[i-1]=='.'||re[i-1]==' ')&&(re[i+1]==','||re[i+1]==39||re[i+1]=='.'||re[i+1]==' '))///左右两边均不是字母
                        {
                            re[i]-=32;
                        }
                    }
                }
            }
            printf("%s\n",re+1);
        }
    }
    return 0;
}
好麻烦QAQ

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值