codeforces C. Fixing Typos 解题报告
题目链接:http://codeforces.com/problemset/problem/363/C
题目意思:纠正两种类型的typos。第一种为同一个字母连续出现3次以上(包括3次);另一种为两个不同的字母各出现2次。需要把使用最少次数而纠正好的word输出来。
为了方便操作,这里我都是通过删去后一个字母来纠正typo的,即如果是wwaattyy,假设看成两组:wwaa和ttyy,那么纠正完的分别是:wwa和tty。至于第一种类型的typo比第二种简便,只需要把同一个字母删除到只剩下2个即可。
注意,这里的删去并不是真的删去,而是通过向应该删去的元素赋值,这里以字符'0'来处理。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
char s[maxn]; int main()
{
int i, j, k, l, len, cnt1, cnt2;
while (gets(s))
{
len = strlen(s);
for (i = ; i < len; i++)
{
cnt1 = ; //统计第一个字母的个数
j = i+;
if (s[i] == s[j] && j < len)
{
cnt1++;
if (cnt1 == ) //相同字母有两个,后面有两种情况
{
//一:这个字母可能有>=3个,此时要删除到只剩下2个(以作标记作为删除)
k = j+;
while (s[j] == s[k] && k < len) //第一类typo
{
s[k] = ''; //删除到只剩下2个
k++;
}
//二:第二类typo
cnt2 = ;
l = k+;
if (s[k] == s[l] && l < len)
{
cnt2++;
if (cnt2 == ) //删除到只剩下一个
{
s[l] = '';
while (s[k] == s[l+] && l+ < len)
{
s[l+] = '';
l++;
}
}
}
}
i = l-;
}
}
for (i = ; i < len; i++)
{
if (s[i] != '') //没有删去的输出
printf("%c", s[i]);
}
printf("\n");
}
return ;
}
codeforces C. Fixing Typos 解题报告的更多相关文章
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
- codeforces 577B. Modulo Sum 解题报告
题目链接:http://codeforces.com/problemset/problem/577/B 题目意思:就是给出 n 个数(a1, a2, ..., an) 和 m,问能不能从这 n 个数中 ...
- codeforces 540B.School Marks 解题报告
题目链接:http://codeforces.com/problemset/problem/540/B 题目意思:给出 k 个test的成绩,要凑剩下的 n-k个test的成绩,使得最终的n个test ...
随机推荐
- GitHub 优秀的 Android 开源项目
转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包括ListView.ActionBar.M ...
- The constructor ClassPathXmlApplicationContext(String) refers to the missing type BeansException
Spring4.X配置一个简单的读取sping的xml的配置文件结果
- JavaScript parser
JavaScript parser 和上面功能有点像,折叠JS代码,快速找到JS中类,方法的工具
- Tomcat Can't load AMD 64-bit .dll on a IA 32
Java.lang.UnsatisfiedLinkError: C:\apache\apache-tomcat-7.0.14\bin\tcnative-1.dll: Can't load AMD 64 ...
- 搭建的SSH 框架
公用JDBC 方法,如果要保存数据,不许再service 中写,而且必须带save* update* 的方法名才受事物控制,ajax 返回json 控制,登录拦截器, 用户体系我没有建立,个人需要不 ...
- struct和union分析实例
1.#include <stdio.h>#include <malloc.h>typedef struct _soft_array{ int len; int ar ...
- 根据某列,将两个 dataframe 合并
import pandas as pd import numpy as np df1 = pd.DataFrame(np.array([['a', 5, 9], ['b', 4, 61], ['c', ...
- Hadoop的datanode无法启动
Hadoop的datanode无法启动 hdfs-site中配置的dfs.data.dir为/usr/local/hadoop/hdfs/data 用bin/hadoop start-all.sh启动 ...
- 思维固化,addTarget难道就只能给self
使用前提 调用某个对象的,一个无参数的方法 如[self.view resignFirstResponder] 注意 [self.view endEdting:YES]就不行,要是无参数的
- (转)MFC的一些宏的整理 (DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE)
很早看了MFC的一些宏的实现,什么RUNTIME_CLASS, DECLARE_DYNAMIC, DECLARE_DYNCREATE,IMPLEMENT_DYNCREATE, etc,看了就烦,现在整 ...