【杭电】[2026]首字母变大写

这里写图片描述

很有意思的一题
这里关键的一是 接触到了除scanf之外的gets输入方法
另一个还是用“开关”x 来表示是不是一个新单词

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

题目地址:【杭电】[2026]首字母变大写

原文地址:https://www.cnblogs.com/BoilTask/p/12570115.html