题目1121:首字母大写

来源:互联网 发布:淘宝卖家运费险要钱吗 编辑:程序博客网 时间:2024/04/27 22:34
题目描述:

对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。
在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。

输入:

输入一行:待处理的字符串(长度小于100)。

输出:

可能有多组测试数据,对于每组数据,
输出一行:转换后的字符串。

样例输入:
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.h>#include <stdlib.h>#include <stdio.h>using namespace std;char str[100];int main() {    while( gets(str) != NULL)    {        int len = strlen(str);        if(str[0] >= 97 && str[0] <= 122)        {            str[0] -= 32;        }        for(int i=1; i<len; i++)        {            if(str[i] == ' ' || str[i] == '\t' || str[i]=='\r' || str[i] == '\n')            {                if(str[i+1] >= 97 && str[i+1] <= 122)                {                    str[i+1] -= 32;                }            }        }        cout<<str<<endl;            }                  return 0;    }/**************************************************************    Problem: 1121    User: Carvin    Language: C++    Result: Accepted    Time:10 ms    Memory:1520 kb****************************************************************/



0 0