http://acm.hdu.edu.cn/showproblem.php?pid=5202

字符串处理的题,要细心。

给定一个只包含小写字母和问号的字符串,让我们还原出本来的字符串,把问号替换成任意字符,如果有多种可能输出字典序最小的,原字符串不能是回文串。

首先判断有没有非法字符,然后是否包含问号,如果没有包含则判断是否是回文串,满足则表示不能还原 。

否则把所有问号都替换成‘a',但是可能构成回文,然后继续替换,直到不是回文为止。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define N 100005
using namespace std; bool palindrome(char *str)
{
int len=strlen(str);
for(int i=;i<len/;i++)
{
if(str[i]!=str[len-i-]) return ;
}
return ;
}
char s[];
int f[];
int main()
{
//Read();
int n;
while(scanf("%d",&n)!=EOF)
{
getchar();
gets(s);
//printf("%s\n",s);
bool flag=;
for(int i=;i<strlen(s);i++)
{
if(!((s[i]>='a'&&s[i]<='z')||s[i]=='?')) {flag=;break;}
}
//printf("%d\n",flag);
if(flag) {printf("QwQ\n");continue;}
for(int i=;i<strlen(s);i++)
{
if(s[i]=='?') {flag=;break;}
}
if(!flag&&palindrome(s)) {printf("QwQ\n");continue;}
int j=;
memset(f,,sizeof(f));
for(int i=;i<strlen(s);i++)
{
if(s[i]=='?')
{
s[i]='a';
f[j++]=i;
}
}
j--;
flag=;
if(palindrome(s))
{
s[f[j]]='b'; //从后往前替换 注意 a??aa
while(palindrome(s))
{
if(j==) {flag=;break;}
j--;
s[f[j]]='b';
s[f[j+]]='a';
}
}
if(flag) printf("QwQ\n");
else
printf("%s\n",s);
}
return ;
}

hdoj - 5202 Rikka with string (BestCoder Round #37 ($))的更多相关文章

  1. hdu.5202.Rikka with string(贪心)

    Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))

    http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...

  3. BestCoder Round #81 (div.2) 1004 String(动态规划)

    题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...

  4. ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  5. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  6. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  7. BestCoder Round #88

    传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...

  8. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  9. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

随机推荐

  1. 日志:slf4j+log4j+maven配置

    代码的日志输出,前前后后折腾了我好几次. 本着会用,快速配置的原则,还是将配置过程记录下来,以便复用. 参考:http://blog.csdn.net/anialy/article/details/8 ...

  2. javascript刷新页面的方法

    Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(locat ...

  3. 1303: [CQOI2009]中位数图

    早起一AC,整天萌萌哒. Problem: 1303 User: forgot93 Language: C++ Result: Accepted Time:56 ms Memory:2108 kb * ...

  4. 非阻塞式JavaScript脚本介绍

    JavaScript 倾向于阻塞浏览器某些处理过程,如HTTP 请求和界面刷新,这是开发者面临的最显著的性能问题.保持JavaScript文件短小,并限制HTTP请求的数量,只是创建反应迅速的网页应用 ...

  5. zend studio插件

    1.安装使用Aptana插件(html,css,js代码提示功能) 安装步骤: 1).zend studio->Help->Install New Software->work wi ...

  6. Java 性能要点:自动装箱/ 拆箱 (Autoboxing / Unboxing)

    [编者按]本文作者为 Ali Kemal TASCI,最早于2016年4月9日发布于DZONE社区.文章主要介绍通过改进 Java 1.5 就已存在的骨灰级特性大幅度提高应用性能. 本文系 OneAP ...

  7. (转)Fibonacci Tilings

    Fibonacci numbers {Fn, n ≥ 0} satisfy the recurrence relation (1) Fn+2 = Fn+1 + Fn, along with the i ...

  8. iOS-CoreImage简单使用

    CoreImage是一个图像框架,它基于OpenGL顶层创建,底层则用着色器来处理图像,这意味着它利用了GPU基于硬件加速来处理图像. CoreImage中有很多滤镜,它们能够一次给予一张图像或者视频 ...

  9. JavaScript. The core.

    Read this article in: Japanese, German (version 2), Arabic, Russian, French, Chinese. An object A pr ...

  10. 谈谈三层架构中Model的作用

    Model又叫实体类,这个东西,大家可能觉得不好分层.包括我以前在内,是这样理解的:UI<-->Model<-->BLL<-->Model<-->DAL ...