OpenJudge百錬練習問題解答(C++)--問題2690:頭文字大文字

1130 ワード

問題:
合計時間制限:
1000ms 
メモリの制限:
65536kB
説明
1つの文字列のすべての単語に対して、単語の頭文字が大文字でない場合、単語の頭文字を大文字にします.文字列では、単語間は空白で区切られ、空白文字には、スペース('')、タブ('t')、リターン('r')、改行記号(')が含まれます.
入力
行を入力:処理する文字列(80未満).
しゅつりょく
≪行の出力|Output Line|emdw≫:変換された文字列.
サンプル入力:
if so, you already have a google account. you can sign in on the right.

サンプル出力:
If So, You Already Have A Google Account. You Can Sign In On The Right.

解:
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
getline(cin,s);
	int InWord=0;
	int h=0;
	while(s[h])
	{
		if(s[h]<='Z'&&s[h]>='A')
		{
			InWord=1;
		}
		if(s[h]<='z'&&s[h]>='a'&&InWord==0)
		{
			s[h]+='A'-'a';
			InWord=1;
		}
		if(InWord==1&&s[h]==' '||InWord==1&&s[h]=='\t'||InWord==1&&s[h]=='\r'||InWord==1&&s[h]=='
') { InWord=0; } h++; } cout<<s; return 0; }