设为首页 加入收藏

TOP

CodeForce 363C Fixing Typos
2015-07-20 18:05:51 来源: 作者: 【 】 浏览:3
Tags:CodeForce 363C Fixing Typos
Fixing Typos time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.

In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).

Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.

Input

The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.

Output

Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters.

If there are multiple solutions, print any of them.

Sample test(s) input
helloo
output
hello
input
woooooow
output
woow
Note

The second valid answer to the test from the statement is "heloo".


题意:给出一个单词,如果这个单词打印错误,删除最少的字母使这个单词变成正确的单词。 出现以下两种情况之一则认为是打印错误: 1.有3个或3个以上连续的字母相同,如helllo 2.有至少2对连续的相同字母,如helloo,hellooww 分析:直接模拟即可,从开头开始,遇到打印错误,就删除一些字母,变成正确单词。
#include
  
   
#include
   
     #include
    
      using namespace std; int main() { string s, str; char ch; while(cin >> str) { s = str[0]; int flag = 0; //flag为0表示到目前为止没有出现连续相同的字母 int len = str.length(); for(int i = 1; i < len; i++) { ch = str[i]; if(ch == s[s.length() - 1]) { if(!flag) { s += ch; flag = 1; } } else { if(ch != s[s.length()-1]) s += ch; } if(s.length() > 3 && s[s.length()-2] != s[s.length()-3] && s[s.length()-1] != s[s.length()-2]) flag = 0; // cout << "s = " << s << ", flag = " << flag << endl; } cout << s << endl; } return 0; }
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 2263 Heavy Cargo(ZOJ 1952) 下一篇HDUJ 1019 Least Common Multiple

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: