首字母变大写

#include <cstdio>
#include <cstring>

int main()
{
    char a[110];
    int len;
    while(gets(a))
    {
        len = strlen(a);
        
        for(int i = 0; i < len-1; ++ i)
        {
            if(i == 0)  // 首字母大写
            {
                a[i] -= 32;
            }
            if(a[i] == ' ')
            {
                a[i + 1] -= 32;
            }
        }
        
        for(int i = 0; i < len; ++ i)
        {
            printf("%c", a[i]);
        }
        printf("\n");
    }
    
    return 0;
}

 

posted @ 2019-07-30 16:45  青衫客36  阅读(163)  评论(0编辑  收藏  举报