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