【CUGBACM15级BC第37场 A】hdu 5202 Rikka with string
来源:互联网 发布:yy制作头像软件 编辑:程序博客网 时间:2024/06/04 21:14
Rikka with string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1577 Accepted Submission(s): 587
Total Submission(s): 1577 Accepted Submission(s): 587
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now they want to recover the string. Yuta remembers that the string only contains lowercase letters and it is not a palindrome string. Unfortunately he cannot remember some letters. Can you help him recover the string?
It is too difficult for Rikka. Can you help her?
One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now they want to recover the string. Yuta remembers that the string only contains lowercase letters and it is not a palindrome string. Unfortunately he cannot remember some letters. Can you help him recover the string?
It is too difficult for Rikka. Can you help her?
Input
This problem has multi test cases (no more than20 ). For each test case, The first line contains a number n (1≤n≤1000) . The next line contains an n-length string which only contains lowercase letters and ‘?’ – the place which Yuta is not sure.
Output
For each test cases print a n-length string – the string you come up with. In the case where more than one string exists, print the lexicographically first one. In the case where no such string exists, output “QwQ”.
Sample Input
5a?bb?3aaa
Sample Output
aabbaQwQ
题目大意:给出一个字符串,字符串中有n个问号,要求你用小写字母填充哪些问号,使得填充完后,字符串的字典序最小且不形成回文,如果无论怎么填充都是回文的话,就输出QwQ
题目大意:处理的话,先将所有问号用填充,然后再考虑是否回文,如果是回文的话,优先修改的应该是最后一个填充位置的字符,如果还是回文的话,就只需修改倒数第二个填充位置的字符,最后一个不变。因为问号大于等于2的话,那么这个字符串必定不会回文了,这里几个陷阱样例
1 ?,输出应该是QwQ
5 aa?aa,输出应该是QwQ
5 a??aa,输出abaaa
注意一下特殊情况,即最后一个问号在中间的情况
#include<cstdio>#include<cstring>#define maxn 1010int n;char str1[maxn], str2[maxn];int mark[maxn];bool check(char *s){ for (int i = 0; i < n / 2; i++) if (s[i] != s[n - 1 - i]) { return false; } return true;}int main(){ while (scanf("%d", &n) == 1) { scanf("%s", str1); int cnt = 0; for (int i = 0; i < n; i++) { str2[i] = str1[i]; if (str1[i] == '?') { str2[i] = 'a'; mark[cnt++] = i; } } str2[n] = '\0'; if (n == 1 && str1[0] == '?') { printf("QwQ\n"); continue; } if (cnt == 0 && check(str1)) { printf("QwQ\n") ; continue; } if (!check(str2)) { printf("%s\n", str2); continue; } str2[mark[cnt - 1]] = 'b'; if (!check(str2)) { printf("%s\n", str2); continue; } if (cnt == 1) { printf("QwQ\n"); continue; } str2[mark[cnt - 2]] = 'b'; str2[mark[cnt - 1]] = 'a'; printf("%s\n", str2); } return 0;}
阅读全文
0 0
- 【CUGBACM15级BC第37场 A】hdu 5202 Rikka with string
- 【CUGBACM15级BC第15场 A】hdu 5083 Love
- 【CUGBACM15级BC第17场 A】hdu 5100 Chessboard
- 【CUGBACM15级BC第23场 A】hdu 5146 Sequence
- 【CUGBACM15级BC第8场 A】hdu 4989 Summary
- 【CUGBACM15级BC第31场 A】hdu 5178 pairs
- 【CUGBACM15级BC第1场 A】hdu 4857 逃生
- 【CUGBACM15级BC第12场 A】【STL】hdu 5058 So easy
- 【CUGBACM15级BC第11场 A】hdu 5054 Alice and Bob
- 【CUGBACM15级BC第13场 A】hdu 5062 Beautiful Palindrome Number
- 【CUGBACM15级BC第18场 A】hdu 5104 Primes Problem
- 【CUGBACM15级BC第20场 A】hdu 5123 who is the best?
- 【CUGBACM15级BC第19场 A】hdu 5108 Alexandra and Prime Numbers
- 【CUGBACM15级BC第21场 A】hdu 5138 CET-6 test
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- 【CUGBACM15级BC第24场 A】hdu 5150 Sum Sum Sum
- 【CUGBACM15级BC第24场 C】hdu 5152 A Strange Problem
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- java:单例模式
- 文章标题
- 计蒜客-树状数组&KMP-Query on a string
- HttpLoggingInterceptor的用法简介
- 工厂模式,抽象工厂模式区别
- 【CUGBACM15级BC第37场 A】hdu 5202 Rikka with string
- my first blog
- 安装qcadoo开源MES的几个坑
- 淘宝tfs-client java配置
- Java-新闻news案例
- LINUX上pycharm远程解释器运行py程序在本地机器上显示plot命令画出来的图像
- 【ExtJs学习笔记】4.DOM操作
- 矩阵快速幂
- PAT-乙级-1016-部分A+B