题解 | #首字母大写#

首字母大写

http://www.nowcoder.com/practice/91f9c70e7b6f4c0ab23744055632467a

easy

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str,temp;
    while (getline(cin, str)) {
        for (int i = 0,j,flag; i < str.size(); ) {
            for (j = i,flag = 0; (str[j] >= 'a' && str[j] <= 'z') ||
                (str[j] >= 'A' && str[j] <= 'Z') || (str[j] >= '0' && str[j] <= '9');++j) {
                flag = 1;
                if (j == i)
                    cout << char(toupper(str[j]));
                else
                    cout << str[j];
            }
            if (flag)
                i = j;
            else
                cout << str[i++];
        }
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务