hdu2026 首字母變大寫

Problem Description
輸入一個英文句子,將每個單詞的第一個字母改成大寫字母。
 
Input
輸入數據包含多個測試實例,每個測試實例是一個長度不超過100的英文句子,佔一行。
 
Output
請輸出按照要求改寫後的英文句子。
 
Sample Input
i like acm i want to get an accepted
 
Sample Output
I Like Acm I Want To Get An Accepted
 
許多已經封裝好的函數能夠讓編程變得大爲簡便。通過這道題,我又瞭解了一個函數:toupper,該函數可以將小寫字母轉化爲大寫字母,使用這個函數的時候,需要頭文件:#include<ctype,h>。

代碼:
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<ctype.h>

using namespace std;
int main(){
	char s[109];
	while(gets(s))
       {
		int n=strlen(s);
		s[0]=toupper(s[0]);
		for(int i=1;i<n-1;i++)
		{
			if(s[i]==' '&&s[i+1]!=' ')
			{
			    s[i+1]=toupper(s[i+1]);
			}
		}
		cout<<s<<endl;
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章