找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; int k;
char s[];
int flag[];
vector<int>ans;
char out[];
int sz;
int dd[]; int main()
{
memset(dd,,sizeof dd);
memset(flag,,sizeof flag);
scanf("%d",&k);
scanf("%s",s);
int len=strlen(s); int L=;
while()
{
int R;
for(int i=L; s[i]; i++)
{
if(s[i]==s[L]) R=i;
else break;
}
if((R-L+)%k!=) flag[s[L]]=;//一定不破
L=R+;
if(L>=len) break;
}
memset(out,,sizeof out);
sz=;
int p=;
while()
{
if(p>=len) break;
if(flag[s[p]]==)
{
out[sz++]=s[p];
p++;
}
else
{
out[sz++]=s[p];
ans.push_back(s[p]);
p=p+k; }
}
for(int i=; i<ans.size(); i++)
if(dd[ans[i]]==)
{
dd[ans[i]]=;
printf("%c",ans[i]);
} printf("\n%s\n",out);
return ;
}

PAT (Advanced Level) 1112. Stucked Keyboard (20)的更多相关文章

  1. PAT (Advanced Level) 1084. Broken Keyboard (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  2. 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)

    题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...

  3. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  4. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  5. PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)

    题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...

  6. PAT (Advanced Level) Practice 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  7. 【PAT Advanced Level】1008. Elevator (20)

    没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...

  8. PAT (Advanced Level) 1108. Finding Average (20)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  9. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

随机推荐

  1. XCode debug中添加查找debug和控制台的办法

    我们每一次编码完成后紧接着便是编译运行起来,看看程序运行的结果是否达到了我们的预期,此时,我们离不开控制台给我们输出必要的信息,为此, 当程序跑起来时,我们的控制台遍自己弹出来,这是不是蛮好的?  又 ...

  2. input[type=number]问题

    有时候对于只能输入数字的表单会有想要写成input[type=number]但是其中有一个问题 <input type="text" name="code" ...

  3. SQL函数学习(一):substring()函数

    秒懂例子: substring('98765',-1,3) 结果:9 substring('98765',0,3) 结果:98 substring('98765',1,3) 结果:987 在操作sql ...

  4. MVC DisplayTemplates and EdiotrTemplates.

    我们在mvc项目里经常要对枚举,日期,副文本输入,我们可以用笨拙的方法去view页面里绑定呈现的html内容,而且这种办法不能重用,也就是在不同的view里还是需要做相同的事情,给个日期空间选择例子吧 ...

  5. wpf之DataTrigger 数据触发器

    wpf中,根据数据的值的不同,UI的界面随之改变(显示控件.隐藏控件以及改变控件的其它属性), 这时我们可以用DataTrigger数据触发器. 下面两个案例实现同样的功能,当条件(数据的值)不同时, ...

  6. js控制日期选择框datetime-local和select的展开

    注: js控制元素展开不受元素css属性的限制,例如opacity,z-index等 1. 使用js控制日期选择框的展开 ios: document.querySelector(".targ ...

  7. 照着例子学习protobuf-python

    以下是照着python操作protobuf进行的protobuf-python的学习笔记: 首先是protobuf的下载与安装: 1 由于google被墙,所以去github上面搜索了一下protob ...

  8. hive学习之WordCount单词统计

    看hive目录下就可以了,程序在hdfs里创建一个hive的大文件夹,相当于数据库吧.上面就是一个完整的利用hive来做单词统计,其中的优劣也能看出一点.

  9. Loadrunner中参数和变量的使用

    //字符串复制strcpy(str,"Hello ") ; //字符串连接strcat(str,"World !");lr_message("str: ...

  10. 批处理 取得当前路径 %CD%

    在DOS的批处理中,有时候需要知道当前的路径.在DOS中,有两个环境变量可以跟当前路径有关,一个是%cd%, 一个是%~dp0. 这两个变量的用法和代表的内容一般是不同的. 1. %cd% 可以用在批 ...