华师大 OJ 2897

题目描述:点击打开链接


值得一提的是:需要把这个用来输出的字符串最后手动补上一个0, tmp[count]='\0';


解决方法:

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

// 1. read in one line into a string str_in[101],预处理对字母部分全部转化成大写字母。
// 2. 从str_in里面读出来,并且判断要不要输出首字母。出去THE,

int main(){
    char str_in[101];
    char *p;
    int k;
    char tmp[101];
    int count;
    while(gets(str_in)>0){

        // Capitalization
        for(k=0;k<strlen(str_in);k++){
            if(str_in[k]<='z' && str_in[k]>='a'){
                str_in[k] = str_in[k] - 'a' + 'A';
            }
        }
        p = str_in;
        while(*p){
            count = 0;
            // 跳过开始空格
            while(*p == ' ' || *p == '-') p++;

            while(*p != ' ' && *p != '-' && *p!='\0'){
                tmp[count++] = *p;
                p++;
            }
            tmp[count]='\0';
            if(strcmp(tmp,"THE")==0 || strcmp(tmp,"OF")==0  || strcmp(tmp,"A")==0 || strcmp(tmp,"FOR")==0 || strcmp(tmp,"AND")==0){
                // Do nothing.
            }else {
                printf("%c",tmp[0]);
            }
            if(*p == '\0') printf("\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值