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数组. 然后在跑的时候,把特殊边都 ...
随机推荐
- MIPI接口
接口 分辨率 说明 RGB 800*480以下 大部分AP均支持RGB接口,此类LCD在低端平板广泛使用 LVDS 1024*768及以上 主要通过转换芯片将RGB等专程LVDS来支持:少量AP直接集 ...
- nginx配置改变默认访问路径
在安装完nginx服务后,url访问的默认路径是安装的路径html文件夹下的内容,如果需要指定自定义的路径,需要配置nginx.conf文件内容,这样通过url访问就可以了,比如: http://12 ...
- bzoj4825
LCT 昨天调试一天没出来,今天推倒重写还是gg了,内心崩溃照着源代码抄,结果发现自己把原树fa和splay的fa一起维护,各种re... 其实我们手玩一下,发现其实树的形态变化很小,那么就可以用lc ...
- 栗染-Myeclispe连接SQL Server数据库
第一步,在SQL server方面 这里是以身份验证登录. 这里我是建了一个hw的数据库,其他没啥说的. 第二步,最主要的一部分 因为第一次连接SQL Server数据库,所以就不知道还有这一步.不然 ...
- 规范化创建一个vs2017 Mvc框架项目
vs2107 + dapper + MiniUi 标准化分层封装使 3.1 规范化创建一个vs2017 Mvc框架项目 此时创建的项目勾选 添加单元测试. 添加一个类库,主要用于实体类操作,类库名称 ...
- spring cloud config搭建说明例子(四)-补充配置文件
服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</groupId> ...
- iOS静态库.Framework制作
首先要解释一下什么是库,库(Library)其实就是一段编译好的二进制代码,加上头文件就可以供别人使用,一般会有两种情况要用到库: 某些代码需要给别人使用,但是我们不希望别人看到源码,就需要以库的形式 ...
- hdu1166 敌兵布阵(树状数组)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 数据传递-------@PathVariable
package com.wh.handler; /** * 通过@PathVariable可以绑定占位符参数到方法参数中,例如 * @PathVariable("userId") ...
- selenium-server 启动命令
启动hub主机: java -jar selenium-server-standalone-2.39.0.jar -role hub 启动node 本地:java -jar selenium-serv ...