比赛 |
NOIP2015普及组练习 |
评测结果 |
WWWWWWWWWW |
题目名称 |
字符串编辑 |
最终得分 |
0 |
用户昵称 |
WangQL. |
运行时间 |
0.012 s |
代码语言 |
C++ |
内存使用 |
0.22 MiB |
提交时间 |
2015-11-05 20:52:47 |
显示代码纯文本
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
string wrong="";
string measured(string x,char y)
{
int num;
for(int i=0;i<x.length();i++)
{
if(x[i]==y)
{
num=i;
break;
}
}
x.erase(num,1);
return x;
}
string measurei(string x,char y,char z)
{
int num;
for(int i=x.length()-1;i>=0;i--)
{
if(x[i]==y)
{ num=i;
break;
}
}
x.insert(num,1,z);
return x;
}
string measurer(string x,char y,char z)
{int count=0;
for(int i=0;i<x.length();i++)
{
if(x[i]==y)
x[i]=z;
count++;
}
if(count!=0)
return x;
else
return wrong;
}
int main()
{
ifstream fin("edit.in");
ofstream fout("edit.out");
char b[41];string a;char object,object1;
char word;
fin.getline(b,'/n');
for(int k=0;k<=strlen(b);k++)
a+=b[k];
fin>>word;
if(word=='D')
{
fin>>object;
fout<<measured(a,object)<<endl;
}
if(word=='I')
{
fin>>object>>object1;
fout<<measurei(a,object,object1)<<endl;
}
if(word=='R')
{
fin>>object>>object1;
if(measurer(a,object,object1)==wrong)
fout<<"error"<<endl;
else
fout<<measurer(a,object,object1)<<endl;
}
fin.close();
fout.close();
return 0;
}