Problem G: 零起点学算法106——首字母变大写

#include<stdio.h>
#include<string.h>
int main(void)
{
    char a[105];
    int i,k;
    while(gets(a)!=NULL)
    {
        k=strlen(a);
        if(a[0]>='a'&&a[0]<='z')
        a[0]-=32;
        for(i=1;i<k;i++)
        {
            if(a[i]==' ')
            {
                if(a[i+1]>='a'&&a[0]<='z')
                {
                a[i+1]-=32;
                }
            }
        }
        printf("%s",a);
        printf("\n");
    }
    return 0;
}

考虑清情况

猜你喜欢

转载自www.cnblogs.com/chenlong991223/p/10088280.html
今日推荐