accepts:395submissions:2281Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) Problem Description
As we know, Rikka is poor at math. Yuta is worrying on this situation, so he gives Rikka some math tasks to practice. There is one of the 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 was only contains lowercase letters and it was 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 have multi test cases (no more than - ). For each test case, the first line contains a number n ( 1 ≤ n ≤ 1000 " . The next line contains a n-length string which only contains lowercase letters and '? ', Haven place which Yuta are not sure .
Output
For each test cases print a n-length string–the string of come up with. In the case where more than one string exists, print the lexicographically rst one. In the case where no such string exists, output "QwQ".
Sample Input
5a?bb?3aaa
Sample Output
Aabbaqwq#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include < Cstring> #include <vector>using namespace std; #define MAXN + 10int M[MAXN], n;string s;bool flag;int Cnt;bool Judge (string str) {int len = str.size (); for (int i=0; i<len/2; i++) {if (s[i]! = S[len-1-i]) return false; } return true; void dfs (int num) {if (flag) return; if (num = = cnt) {if (!judge (s)) {cout<<s<<endl; Flag = true; } return; } for (char i= ' a '; i<= ' z '; i++) {S[m[num]] = i; DFS (num + 1); } return; int main () {while (~SCANF ("%d", &n)) {flag = false; CNT = 0; cin>>s; Memset (M,-1, sizeof (m)); for (int i=0; i<n; i++) {if (s[i] = = '? ') m[cnt++] = i; } if (!cnt) { if (!judge (s)) cout<<s<<endl; else cout<< "QwQ" <<endl; } else {DFS (0); if (!flag) cout<< "QwQ" <<endl; } }}
Rikka with string