STL 水题 Fixing Typos(string 容器)

来源:互联网 发布:淘宝内衣买家晒图 编辑:程序博客网 时间:2024/05/18 12:02

题目连接 http://codeforces.com/problemset/problem/363/C


//string容器


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


using namespace std;
char str[210000];
int main()
{  
int f1,f2,i;


string s;



while(gets(str))
{
s=str;
f1=0;
string::iterator it=s.begin();
for(;it!=s.end();it++)
{
if(f1&&*it==*(it+1))//例如:hhggggghh 则x=4 删除后:hhghh
{
int x;
x=1;
while(*it==*(it+x))
x++;
s.erase(it+1,it+x);

}
f1=0;
if(*it==*(it+1))//例如:hhhhhhhhhhgghhh  则x=8 删除后:hhgghhh
{
int x;
f1=1;
if(*it==*(it+2))
{
x=2;
while(*it==*(it+x))
x++;
s.erase(it+2,it+x);
}
it++;
}


}
cout<<s<<endl;
}
return 0;
}

原创粉丝点击