CodeForces 363C - Fixing Typos
来源:互联网 发布:光棍儿 知乎 编辑:程序博客网 时间:2024/06/02 03:18
Many modern text editors automatically check the spelling of the user'stext. Some editors even suggest how to correct typos.
In this problem your task to implement a small functionality to correcttwo types of typos in a word. We will assume that three identical letterstogether is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical lettersimmediately followed by another couple of identical letters is a typo too (forexample, 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 fromboth 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 andis 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次
2、 两对字符相连
代码:#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){int len;char temp[200005];while (scanf("%s", temp) != EOF){char c;string st;int l = strlen(temp);int i;bool flag = false;st = temp[0];for (i = 1; i<l; i++){c = temp[i];len = st.length();if (c == st[len - 1]){if (!flag){st += c;flag = true;}}elsest += c;len = st.length();if (len>3 && st[len - 1] != st[len - 2] && st[len - 2] != st[len - 3])flag = false;}cout << st << endl;}return 0;}
- CodeForces 363 C. Fixing Typos
- Codeforces 363C. Fixing Typos
- CodeForces 363C - Fixing Typos
- codeforces 363C Fixing Typos
- CodeForces 363C Fixing Typos
- Problem - 363C - Codeforces --C. Fixing Typos
- CodeForce 363C Fixing Typos
- Codeforces 363C Fixing Typos 贪心+字符串模拟
- Fixing Typos CodeForces
- C. Fixing Typos
- C. Fixing Typos----栈
- Fixing Typos
- STL 水题 Fixing Typos(string 容器)
- codeforces 363C
- Fixing TCriticalSection
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) [C] Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- java多线程设计模式--Balking不需要就算了
- UVALive 6912
- android-percent-support-extend根据百分比高效自动适配页面库。
- 【数据结构|剑指Offer】单向链表的各项操作实现
- jquery 深入学习笔记之一 (事件绑定)
- CodeForces 363C - Fixing Typos
- Mac 程序员必备软件
- 玩转HTML5移动页面(动效篇)
- Java Socket编程
- 【计蒜客系列】挑战难题23:计数和数数
- Ubuntu14.04建立WIF热点供手机和平板上网
- ajaxfileupload 始终不执行success 只执行error方法;SyntaxError: expected expression, got '<
- 日经社説 20150727 補正予算を含め歳出を厳しく管理せよ
- 通过伪造CA证书,实现SSL中间人攻击