codeup-首字母大写

参考大佬的链接:https://blog.youkuaiyun.com/Iridescent1018/article/details/100152681

#include <stdio.h>
#include <string.h>

int main(){
    char str[110];
    while(gets(str)){
        int len = strlen(str);
        //对第一个字符单独处理  特例是第一个字符为空白字符 
        //即" nihao" 输出还需是" nihao",而不是" Nihao" 
        if(str[0]>'Z'){
            str[0] = str[0] + 'A' - 'a';
        }
        for(int i=1; i<len; i++){
            if(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n'){
                while(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n'){
                    i++;
                }
                if(str[i]>'Z'){
                    str[i] = str[i] + 'A' - 'a';
                }
            }
        }
        printf("%s\n", str);
    }
    return 0;
}

/*
//错在没考虑第一个字符时空白字符的情况! 
int main(){
    char s[110];
    while(gets(s)){
        int len=strlen(s);
        int str[110][110], row=0, col=0;
        for(int i=0; i<110; i++){
            for(int j=0; j<110; j++){
                str[i][j] = '\0';
            }
        }
        for(int i=0; i<len; i++){
            if((s[i]!=' ')&&(s[i]!='\t')&&(s[i]!='\r')&&(s[i]!='\n')){
                str[row][col++] = s[i];
            }else{
                str[row][col] = '\0';
                row++;
                col = 0;
            }
        }
        for(int i=0; i<=row; i++){
            if(str[i][0]>='A' && str[i][0]<='Z'){
                printf("%c", str[i][0]);
            }else if(str[i][0] >'Z'){
                printf("%c", (str[i][0]+'A'-'a'));
            }
            col = 1;
            while(str[i][col] != '\0'){
                printf("%c", str[i][col]);
                col++;
            }
            printf(" ");
        }
        printf("\n");
    }
    return 0;
}
*/
 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值