codeforces 372 Complete the Word(双指针)
codeforces 372 Complete the Word(双指针)
题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N=5e4+10;
char a[N];
int book[30];
int main()
{
while(~scanf("%s",a))
{
int i=0,j=0,len=strlen(a);
int u,v;
memset(book,0,sizeof(book));
for(j=0;j<len;j++)
{
if(j-i==26) break;
if(a[j]=='?') continue;
else if(book[a[j]-'A'])
{
while(i<j&&a[i]!=a[j]){
if(a[i]=='?'){
i++;
continue;
}
else book[a[i]-'A']=0;
i++;
}
if(i!=j){
i++;
}
}
else book[a[j]-'A']=1;
}
if(j-i!=26){
puts("-1");
continue;
}
int kk=0;
memset(book,0,sizeof(book));
for(int k=i;k<j;k++){
if(a[k]!='?') book[a[k]-'A']=1;
}
for(int k=i;k<j;k++){
if(a[k]=='?'){
for(;kk<26;kk++){
if(!book[kk]){
a[k]=kk+'A';
book[kk]=1;
break;
}
}
}
}
for(int k=0;k<len;k++){
if(a[k]=='?'){
a[k]='A';
}
}
printf("%s\n",a);
}
return 0;
}
codeforces 372 Complete the Word(双指针)的更多相关文章
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Complete the Word CodeForces - 716B
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring ...
- Codeforces 372 B. Counting Rectangles is Fun
$ >Codeforces \space 372 B. Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...
- Codeforces 372
A (被装的袋鼠不可以装的袋鼠)贪心,排序,从n/2分成两部分. B 好一道前缀和的题目. C 标准算法不难想,m^2的算法见http://codeforces.com/blog/entry/9907 ...
- Complete the Word
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring ...
- CodeForces 715B Complete The Graph 特殊的dijkstra
Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...
随机推荐
- POJ2503 Babelfish map或者hash_map
POJ2503 这是一道水题,用Map轻松AC. 不过,可以拿来测一下字符串散列, 毕竟,很多情况下map无法解决的映射问题需要用到字符串散列. 自己生成一个质数, 随便搞一下. #include&l ...
- java笔记线程两种方式模拟电影院卖票
public class SellTicketDemo { public static void main(String[] args) { // 创建三个线程对象 SellTicket st1 = ...
- 如何在 ubuntu 12.04 上安装 skype(转载)
转自:http://blog.51osos.com/linux/how-to-install-skype-in-ubuntu-12-04/ 添加Canonical Partner Repository ...
- CentOS 6.5克隆后eth1与eth0的问题
CentOS 6.5克隆后eth1与eth0的问题 按照安装文档执行以下步骤时: 从克隆出来的虚拟机网卡都会被命名为eth1,而有些程序或者脚本,涉及到网卡的,默认写的是eth0,这时就存在要 ...
- jQuery多项选择器
jQuery多项选择器模式: $("selector1,selector2,selectorN"); 将每一个选择器匹配到的元素合并后一起返回,可以指定任意多个选择器,并将匹配到的 ...
- c++ swap函数
swap(a,b)也就是把a和b的值互换. 头文件:#include<algorithm>,swap要加using namespace std:
- Redis集群创建和配置
1.检查GCC是否安装,可以看看版本号 gcc -v 安装命令:yum install gcc-c++ 2.安装Ruby和Rubygems 如果有网的话,则通过yum命令进行安装,自动将关联的依赖包全 ...
- Get 和 Post 使用篇(1)
1.Post 请求发送方式 实例: const string sResponseEncoding = "gb2312"; //测试文本信息 string postText = &q ...
- 华硕(ASUS)X554LP笔记本一开机就进入aptio setup utility 问题的解决
某次因大意一直未插电,华硕(ASUS)X554LP笔记本后来没电关机.后来每次一开机就进入aptio setup utility界面,按F9调入默认配置,F10保存后退出,重启仍然进入aptio se ...
- mongo 3.4分片集群系列之四:搭建分片集群--哈希分片 + 安全 + 区域
这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...