Uppercase
Time Limit: 2000/1000ms (Java/Others)
Problem Description:
给出一句中间无特殊符号的英语句子,要求将各单词的首字母改大写。
Sample Input:
3
hello world!
i am understand!
how are you!
Sample Output:
Hello World!
I Am Understand!
How Are You!
解题思路:水题!!!思路很简单,先将首字母改成大写,再依次遍历字符串,当a[i-1]是空格字符' '且a[i]是小写字母时,就将其换成大写字母,水过。
杭电hdu2026与此题一样,题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2026
AC代码:
1 #include<bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 char a[101];int n;
6 cin>>n;getchar();
7 while(n--){
8 gets(a);
9 if(a[0]>='a'&&a[0]<='z')a[0]=a[0]-32;
10 for(int i=2;i<(int)strlen(a);i++)
11 if(a[i-1]==' ' && (a[i]>='a'&&a[i]<='z'))a[i]-=32;
12 cout<<a<<endl;
13 }
14 return 0;
15 }