hihoCoder - 1082 - 然而沼跃鱼早就看穿了一切(字符串处理)

来源:互联网 发布:什么是谷歌seo 编辑:程序博客网 时间:2024/04/30 00:47

题意:给你一串字符串,要求把字符串中出现的“marshtomp”全部换成“fjxmlhx”,且不区分大小写


思路:在处理的时候不区分大小写,但注意,输出的时候要考虑大小写,我用了两个数组,一个纯小写用于判断,另外一个用来输出

/*************************************************************************    > Author: violet0908    > Mail: 605654408@qq.com     > Created Time: 2015年07月22日 星期三  ************************************************************************/#include<cstdio>#include<cstring>#include<cctype>char b[]={"marshtomp"};int judge(char str[], int n){    for(int i = 0; i < 9; i++){        if(str[i+n] != b[i])            return 0;    }    return 1;}int main() {    char str1[210], str2[210];    char a[]={"fjxmlhx"};    int ll = strlen(b);    while(gets(str1)){        int len = strlen(str1);        strcpy(str2, str1);        for(int i = 0; i < len; i++)            str2[i] = tolower(str2[i]);        for(int i = 0; i < len;){            if(str2[i]=='m' && judge(str2, i)){                printf("%s", a);                i+=9;            }            else{                printf("%c", str1[i]);                i++;            }        }        printf("\n");    }    return 0;}
0 0
原创粉丝点击