HDU 2026 首字母变大写
题目里面确实所有字母都是小写,没有那种本来就是大写的坑。
值得留意的是可能会出现多个连续的空格(也不一定,我自己测试的时候添加判断了),这个我处理了
也就是上一个不是字母并且当前是字母,才变大写。
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
bool isnotC(char c)
{
if(!(c>='a' && c<='z') && !(c>='A' && c<='Z'))
return true;
else
return false;
}
void main()
{
char str[105];
while(gets(str))
{
int len = strlen(str);
for(int i=0;i<len;i++)
{
if(i == 0)
str[i] = str[i]-32;
else if(isnotC(str[i-1])&& !isnotC(str[i]))
str[i] = str[i]-32;
else
continue;
}
printf("%s\n",str);
}
}