HDU 5202
来源:互联网 发布:货车软件 编辑:程序博客网 时间:2024/06/05 20:18
Rikka with string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1248 Accepted Submission(s): 441
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 ($)
Recommend
hujie | We have carefully selected several similar problems for you: 5426 5425 5424 5423 5422
模拟题。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <string>#include <math.h>#include <vector>#include <stdlib.h>using namespace std;typedef long long ll;char str[1005];int a[1005];bool ishuiwen(int len){ int i; for(i=0; i<len/2; i++) { if(str[i]!=str[len-1-i]) break; } if(i==len/2) return 1; else return 0;}int main(){ int n,i; while(cin>>n>>str) { int flag=0; memset(a,0,sizeof(a)); for(i=0; i<n; i++) { if(str[i]=='?') { a[i]=1; str[i]='a'; } } if(!ishuiwen(n)) cout<<str<<endl; else { for(i=n-1; i>=0; i--) { if(a[i]) { if(i!=n/2 || n%2==0) { str[i]='b'; flag=1; break; } } } if(flag) cout<<str<<endl; else cout<<"QwQ"<<endl; } } return 0;}
0 0
- hdu 5202
- HDU 5202
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- Hadoop 运行wordcount 实例
- 网络虚拟化相关
- 从头开始实现一个神经网络
- Mac 配置ruby环境之zsh vim
- Android View.OnTouchListener 的子类,AutoScrollHelper,ZoomButtonsController,ListViewAutoScrollHelper
- HDU 5202
- Hopfield's associative memory network
- Android ListView —— Adapter, BaseAdapter, RecycleBin
- POJ 2083 Fractal
- 基于SCN的查询(AS OF SCN)
- CURL抓取网页内容并用正则提取。
- 中断机制与内核定时器
- 将你的Vim 打造成轻巧强大的IDE
- 二级c++——基本操作题小结