HDU-2026 首字母变大写

来源:互联网 发布:数据分析需要的技能 编辑:程序博客网 时间:2024/05/16 10:59

HDU-2026 首字母变大写

题目大意:将一句英语语句中的所有单词首字母变成大写

Sample Input

i like acm
i want to get an accepted

Sample Output

I Like Acm
I Want To Get An Accepted

解题思路:先将首字母变成大写,然后每当遇到空格且空格后面是字母,则将字母变成大写。

#include <iostream>using namespace std;int main() {    char s[500];    while (gets_s(s) != NULL) {        int len = strlen(s);        if (s[0] >= 97 && s[0] <= 122)            s[0] -= 32;        for (int i = 0; i < len; i++) {            if (s[i] == 32 && (s[i + 1] >= 97 && s[i + 1] <= 122))                s[i + 1] -= 32;        }        cout << s << endl;    }    return 0;}
0 0
原创粉丝点击