Fixing Typos CodeForces
来源:互联网 发布:python buffer类型使用 编辑:程序博客网 时间:2024/06/07 03:58
大致题意:个人感觉题目描述的不是很清楚,一开始理解错了。大致意思分为两种情况:1> 不能出现三个或者三个以上连续相同的字母 2>不能出现两个不同字母连续如aabb是不符合题意的。让你删除最少的字母得到符合题意的数组,可能有多组数据符合题意输出任意一组就行!!!
解题思路:开两个数组,边比较边存!!!看代码一目了然
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.
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.
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.
helloo
hello
woooooow
woow
The second valid answer to the test from the statement is "heloo".
#include<stdio.h>#include<string.h>char s[200010],str[200010];int main(){ scanf("%s",str); int t=0,i,j; //只能赋给前两个值,因为超过两个可能出现三个相同的无法判断 s[t++]=str[0]; s[t++]=str[1]; for(i=2;i<strlen(str);i++) { char ch=str[i]; //三个或以上连续相同的字母或者两个不同字母连续出现两次如aabb if((ch==s[t-1]&&s[t-2]==s[t-3])||(ch==s[t-1]&&s[t-1]==s[t-2])) continue; else s[t++]=ch; } s[t]='\0'; printf("%s\n",s); return 0;}
- Fixing Typos CodeForces
- 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
- Fixing Typos
- Codeforces 363C Fixing Typos 贪心+字符串模拟
- C. Fixing Typos
- C. Fixing Typos----栈
- CodeForce 363C Fixing Typos
- STL 水题 Fixing Typos(string 容器)
- Fixing TCriticalSection
- Fixing AJAX: XMLHttpRequest
- Fixing Venture Capital
- Fixing "Base SDK Missing"
- Fixing the Errant Microphone
- 第一篇:JAVA之基础学习线路图
- POJ 1328 Radar Installation(贪心)
- ThreadPoolExecutor线程池
- 【hdu 1232】 畅通工程
- Python第三方组件
- Fixing Typos CodeForces
- Android零基础入门第23节:ImageButton和ZoomButton使用大全
- 移动端基础知识
- Python3输入输出与数据类型
- mysql 存储过程游标
- int 类的属性和方法
- mybatis访问数据库时报java.lang.NullPointerException
- mybatis的嵌套查询和延迟加载分析
- LARC DL笔记(二) 训练自己的img