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(双指针)的更多相关文章

  1. 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 ...

  2. CodeForces 716B Complete the Word

    题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...

  3. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  4. 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 ...

  5. Complete the Word CodeForces - 716B

    ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring  ...

  6. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

  7. Codeforces 372

    A (被装的袋鼠不可以装的袋鼠)贪心,排序,从n/2分成两部分. B 好一道前缀和的题目. C 标准算法不难想,m^2的算法见http://codeforces.com/blog/entry/9907 ...

  8. Complete the Word

    ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring ...

  9. CodeForces 715B Complete The Graph 特殊的dijkstra

    Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...

随机推荐

  1. 698C

    Description n个视频,长度为k的缓存,每次询问,每个视频以pi的概率被选,如果不在缓存区则加入,如果缓存区满了,则最先进缓存的出来,问10^100次操作以后每个视频在缓存的概率 Input ...

  2. SpringBoot中使用spring-data-jpa 数据库操作(下)

  3. 为了一个句号,写了好多行的代码——值!(html 表单的处理)

    个人信息表 <span style="font-size:18px;"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ...

  4. hdu 1043 Eight

    欸我一直以为双向bfs是搜完一半再搜另一半呢,妹想到是两个一起搜 然后队列里放的结构体里不能直接存答案,所以做一个邻接表一样的东西,直接指向需要的字符即可 记录状态用康托展开来hash 以及居然是多组 ...

  5. bzoj 1626: [Usaco2007 Dec]Building Roads 修建道路【最小生成树】

    先把已有的边并查集了,然后MST即可 记得开double #include<iostream> #include<cstdio> #include<algorithm&g ...

  6. Nginx(一) 安装基于centos7

    1.   nginx介绍 1.1. 什么是nginx Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开 ...

  7. echart 参数 vue配置 图文展示

    https://blog.csdn.net/she_lover/article/details/51448967 https://blog.csdn.net/n_meng/article/detail ...

  8. Spring中bean的作用域与生命周期

    在 Spring 中,那些组成应用程序的主体及由 Spring IOC 容器所管理的对象,被称之为 bean.简单地讲,bean 就是由 IOC 容器初始化.装配及管理的对象,除此之外,bean 就与 ...

  9. 乐搏讲自动化测试-Python发展背景(1)

    相信小伙伴们都知道,随着软件测试行业的发展和进步自动化测试已经成为必然.在竞争日益激烈的市场环境中也是你升职加薪的利器. 所以,小编决定从今天起!将要系统.连续.高质量的持续更新「整套自动化测试」文章 ...

  10. [转].net cookie版购物车

    本文转自:http://www.sulong.cc/article/program/aspx/110613114249.html #region 添加到购物车AddShoppingCar /// &l ...