对于char
char s[100];
cin.getline(s,1000);//第二个参数表示允许输入的最大长度while(cin.getline(s,1000));
输入输出样例
输入:He llo
输出:He llo
对于string
string s;
getline(cin,s);while(getline(cin,s));
输入输出样例
输入:He llo
输出:He llo
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入
输入包括多行。
每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。
输出
输出包含多行,为输入按照描述中变换的结果。
The Marshtomp has seen it all before. marshTomp is beaten by fjxmlhx! AmarshtompB样例输出
The fjxmlhx has seen it all before. fjxmlhx is beaten by fjxmlhx! AfjxmlhxB
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
string s,ss;
int i,len,j;
ss="fjxmlhx";
while(getline(cin,s))
{
len=s.length();
for(i=0;i<len-8;i++)
{
if((s[i]=='M'||s[i]=='m')&&(s[i+1]=='a'||s[i+1]=='A')&&(s[i+2]=='r'||s[i+2]=='R')
&&(s[i+3]=='s'||s[i+3]=='S')&&(s[i+4]=='h'||s[i+4]=='H')&&(s[i+5]=='t'||s[i+5]=='T')
&&(s[i+6]=='o'||s[i+6]=='O')&&(s[i+7]=='m'||s[i+7]=='M')&&(s[i+8]=='p'||s[i+8]=='P'))
s.replace(i,9,ss);
}
cout<<s<<endl;
}
}