PAT (Advanced Level) 1112. Stucked Keyboard (20)
找出一定没问题的字符(即一连串的额字符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)的更多相关文章
- PAT (Advanced Level) 1084. Broken Keyboard (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)
题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...
- PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)
题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...
- PAT (Advanced Level) Practice 1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- 【PAT Advanced Level】1008. Elevator (20)
没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...
- PAT (Advanced Level) 1108. Finding Average (20)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1100. Mars Numbers (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
随机推荐
- ios中获取当前屏幕尺寸的方法
//获取当前屏幕尺寸 CGRect screenFrame = [UIScreen mainScreen].bounds; int screenWidth = screenFrame.size.wid ...
- php curl调用相关api
一.基本步骤 1.本次模拟是php的相关post请求,可通过CURLOPT_CUSTOMREQUEST设定相关POST.GET.PUT.DELETE相关适应REST API 2.相关重要的是curl_ ...
- 《Windows驱动开发技术详解》之定时器
I/O定时器 I/O定时器是DDK提供的一种定时器.它每个1s钟系统会调用一次I/O定时器例程.I/O定时器例程运行在DISPATCH_LEVEL级别,因此在这个例程中不能使用分页内存,否则会引起页故 ...
- Linux平台从文件中查找字符赋值于变量
以telnet方式登录Linux主机,在默认目录下用命令创建一个包含DUT wanIP的文本文件.[root] echo wanIP=88.0.100.253 > ./wanIP.txt在默认目 ...
- 递归解析任意层的json
package com.sun.test; import java.util.Iterator; import net.sf.json.JSONArray;import net.sf.json.JSO ...
- The 3n + 1 problem
The 3n + 1 problem Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- javascript模糊查询一个数组
/* * 模糊查询一个数组 */ com.ty.repairtech.JsonOperation.searchList = function(str, container) { var newList ...
- 特殊字符 js处理
2.特殊字符传递过程中的处理 (1)js页面的处理 var url= "#@+&这些带有特殊字符"; url=encodeURI(encodeURI(url));//转码两 ...
- phpStorm设置显示代码行号
File->Settings
- phpStorm 2016.1.2 最新版激活方法【亲测可用】
测试日期:2016-07-29 下载地址:https://yunpan.cn/c6mWAGbExcyjf 访问密码 00fb 1.windows版本 菜单help >>>> ...