CodeForces - 363C Fixing Typos

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.

Example
Input
helloo
Output
hello
Input
woooooow
Output
woow
Note

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

      纠错。。。is纠错。。

附两种代码:

#include<stdio.h>
#include<string.h>
char s[201000];
int main()
{
    while(~scanf("%s",s))
    {
        int l=strlen(s);
        if(l<3)
        {
            printf("%s",s);    //<3肯定成立
        }
        else
        {
            printf("%c%c",s[0],s[1]);
            for(int i=2; i<l; i++)
            {
                if(s[i]==s[i-1]&&s[i-1]==s[i-2])continue;  //三个相同的情况
                else if(i>=3)
                {
                    if(s[i]==s[i-1]&&s[i-2]==s[i-3])
                    {
                        s[i-1]=s[i-2];            //变为三个相同的情况
                    }
                    else printf("%c",s[i]);
                }
                else printf("%c",s[i]);
            }
        }
    }
 return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char s1[201000],s2[201000];
    while(~scanf("%s",s1))
    {
        int l=strlen(s1);
        int top=0;
        s2[top++]=s1[0];
        s2[top++]=s1[1];
        for(int i=2;i<l;i++)
        {
            if(s1[i]==s2[top-1]&&s2[top-1]==s2[top-2])    //看的别人的,不知道为什么不能改为s1[i-1]&&s2[i-1]==s1[i-2]之类的,,,
                continue;
            if(s1[i]==s2[top-1]&&s2[top-2]==s2[top-3])   
                continue;
            s2[top++]=s1[i];
        }
        s2[top]='\0';
        printf("%s\n",s2);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值