HDU - 5202 - Rikka with string (DFS)
来源:互联网 发布:win7恢复网络设置 编辑:程序博客网 时间:2024/04/30 23:01
Rikka with string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 214 Accepted Submission(s): 109
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 than 20 ). 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
Source
BestCoder Round #37 ($)
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>#define LL long long using namespace std;char str[1005];int len;int flag;int judge() { for(int i = 0; i <= len / 2; i++) { if(str[i] != str[len - i - 1]) return 1; } return 0;}void dfs(int x) { if(flag == 0) return; if(x == len) { if(judge()) { printf("%s\n", str); flag = 0; } return; } if(str[x] <= 'z' && str[x] >= 'a') { dfs(x + 1); return; } if(str[x] == '?') { for(int i = 'a'; i <= 'z'; i++) { str[x] = (char)i; dfs(x + 1); str[x] = '?'; } }}int main() { int n; while(scanf("%d", &n) != EOF) { scanf("%s", str); len = strlen(str); flag = 1; dfs(0); if(flag) { printf("QwQ\n"); } } return 0;}
0 0
- HDU - 5202 - Rikka with string (DFS)
- HDU 5202 Rikka with string (水DFS)
- HDU-5202-Rikka with string(DFS + WrongAnswer)
- hdu 5202 Rikka with string(模拟)
- hdu 5202 Rikka with string
- HDU 5202 Rikka with string
- HDU 5202 Rikka with string
- hdu 5202 Rikka with string
- hdu 5202 Rikka with string
- HDU 5202 Rikka with string
- hdu 5202 Rikka with string
- hdu 5423 Rikka with Tree(dfs)
- HDU 5423 Rikka with Tree(DFS)
- Rikka with String HDU
- HDU - 5202 Rikka with string 贪心
- Rikka with string(较难DFS+回文判断)
- hdu 5423 Rikka with Tree DFS
- BestCoder #37 Rikka with string (hdu 5205)
- win7 下修改无限网卡Mac地址
- lib和dll文件的区别和联系
- Android Studio系列教程六--Gradle多渠道打包
- 笔记本之间大文件相传
- 2015 - 04 - 11
- HDU - 5202 - Rikka with string (DFS)
- java利用SWFUpload实现文件批量上传
- unbuntu中改变shell时,输入chsh,在输入密码,提示PAM的验证失败问题的解决
- 第6题
- el表达式跟ognl表达式的区别(用法和页面取值)
- UVA - 11464 - Even Parity
- 文章标题
- 初学单元测试框架Mockito
- 04-树5. Complete Binary Search Tree (30)