被阴2号

08:字符替换

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

把一个字符串中特定的字符全部用给定的字符替换,得到一个新的字符串。

输入
只有一行,由一个字符串和两个字符组成,中间用单个空格隔开。字符串是待替换的字符串,字符串长度小于等于30个字符,且不含空格等空白符;
接下来一个字符为需要被替换的特定字符;
接下来一个字符为用于替换的给定字符。
输出
一行,即替换后的字符串。
样例输入
hello-how-are-you o O
样例输出
hellO-hOw-are-yOu
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
char a[5000];
char k1,k2;
int n;
int main()
{
    int i,j=0;
    gets(a);
    cin>>k1>>k2;
    n=strlen(a);
    for(i=0;i<n;i++)
    {
       if(a[i]==k1) cout<<k2;
       else cout<<a[i];    
    }
    
return 0;
}
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
char a[5000];
char k1,k2;
int n;
int main()
{
    int i,j=0;
    cin>>a;
    cin>>k1>>k2;
    n=strlen(a);
    for(i=0;i<n;i++)
    {
       if(a[i]==k1) cout<<k2;
       else cout<<a[i];    
    }
    
return 0;
}
原文地址:https://www.cnblogs.com/voldemorte/p/7197887.html