CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B
题目大意:
给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘?’表示占位符可表示字母),如果存在则输出该字串‘?’位置用替换后的字母代替,其他不在子串中的‘?’用字母代替即可。如果该字串不存在满足条件的子串,则输出-1.
举例:
----------------------------------
ABC??FGHIJK???OPQR?TUVWXY?
ABCDEFGHIJKLMNOPQRZTUVWXYS
------------
ABC??FGHIJK???OPQR?TUVWXY?WW??W
ABCDEFGHIJKLMNOPQRZTUVWXYSWWAAW
-------------
AABCDEFGHIJKLMNOPQRSTUVW??M
-1
--------------------------------------
解题思路:
暴力即可。
首先判断是否满足长度为26,<26 直接输出 -1.
否则:双重for 扫描,内循环每次从 i -> i+25 即可,如果 字符出现的个数+?的个数=26,则该子串满足,则记录左边的下标即可。
然后找出没有出现的字符,放在数组x[]。for循环,从记录下标开始-》下标+25,如果是‘?’,则用x[k++]代替‘?’。替换完子串‘?’,遍历整个字串,如果是‘?’用‘A’代替即可。
然后输出。
-->本次代码写low了。。。见谅。
AC Code:
#include<bits/stdc++.h>
using namespace std;
const int N=+;
char ca[N];
int main()
{
int i,j; while(scanf("%s",ca)!=EOF)
{ if(strlen(ca)<)
{
printf("-1\n");
continue;
}
int cut,l,r,w;int dp[];
for(i=; i<strlen(ca); i++)
{
memset(dp,,sizeof(dp));
cut=w=l=r=;
for(j=i; j<i+; j++)
if(ca[j]=='?')w++;
else if(!dp[ca[j]]&&(int)ca[j]!=)
++cut,dp[ca[j]]=;
if(cut+w==)
{
l=i;
r=l+;
break;
}
}
if(r==)
{
printf("-1\n");
continue;
}
else
{
char s[],tem[];
int k=,x,w;
for(x=l; x<=l+; x++)
if(dp[ca[x]])s[k++]=ca[x];
k=;
for(x=; x<=; x++)
{
int flag=;
for(w=; w<strlen(s); w++)
{
if((int)s[w]-'A'==x)
{
flag=;
break;
}
}
if(flag)tem[k++]=(char)(x+'A');
}
k=;
for(x=l; x<=l+; x++)
if(ca[x]=='?')ca[x]=tem[k++];
for(i=; i<strlen(ca); i++)
if(ca[i]=='?')ca[i]='A';
puts(ca);
}
}
return ;
}
CodeForces 716B 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 372 Complete the Word(双指针)
codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...
- 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 ...
- 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数组. 然后在跑的时候,把特殊边都 ...
- Codeforces 1182D Complete Mirror [树哈希]
Codeforces 中考考完之后第一个AC,纪念一下qwq 思路 简单理解一下题之后就可以发现其实就是要求一个点,使得把它提为根之后整棵树显得非常对称. 很容易想到树哈希来判结构是否相同,而且由于只 ...
- Codeforces 1182D Complete Mirror 树的重心乱搞 / 树的直径 / 拓扑排序
题意:给你一颗树,问这颗树是否存在一个根,使得对于任意两点,如果它们到根的距离相同,那么它们的度必须相等. 思路1:树的重心乱搞 根据样例发现,树的重心可能是答案,所以我们可以先判断一下树的重心可不可 ...
随机推荐
- Java--剑指offer(7)
31.求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.AC ...
- Mybatis 异常: The content of elements must consist of well-formed character data or markup
原因很简单:在ibatis的配置文件中不能出现小于号(>) <delete id="deleteByPrimaryKey" parameterType=&quo ...
- 用ElasticSearch和Protovis实现数据可视化
搜索引擎最重要的目的,嗯,不出意料就是搜索.你传给它一个请求,然后它依照相关性返回你一串匹配的结果.我们可以根据自己的内容创造各种请求结构,试验各种不同的分析器,搜索引擎都会努力尝试提供最好的结果. ...
- iOS不得姐项目--pop框架的初次使用
一.pop和Core Animation的区别 1.Core Animation的动画只能添加到layer上 2.pop的动画能添加到任何对象 3.pop的底层并非基于Core Animation,是 ...
- spoj705 后缀数组求不同子串的个数
http://www.spoj.com/problems/SUBST1/en/ 题目链接 SUBST1 - New Distinct Substrings no tags Given a stri ...
- JSP 中的 tag 文件
在jsp文件中,可以引用 tag 和tld 文件,本文主要针对 tag 对于tag 文件 1)将此类文件放在 WEB-INF 下,比如 /WEB-INF/tags,tags 是目录,其下可以有多个.t ...
- 回到顶端js实现
function goTop(){ var _btn = document.getElementById("goTop"); if (document.documentElemen ...
- jQuery中data()方法用法实例
语法结构一: 复制代码代码如下: $(selector).data(name,value) 参数列表: 参数 描述 name 存储的数据名称. value 将要存储的任意数据. 实例代码: 复制代码代 ...
- perl sub
#/usr/bin/perl -w use strict; my $usage = "\n\nusage: $0 <length>\n\n"; my $length = ...
- jquery插件-表单验证插件-提示信息中文化与定制提示信息
接上一篇 2)messages 提示:修改默认的提示信息最简单的方法是引入message_zh.js文件即可! 如果需要在validate()方法内提示则可以使用本选项 类型:Object 说明:自定 ...