Rikka with string

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.