Rikka with string bc#37

Source: Internet
Author: User

Rikka with string

accepts:395

submissions:2281
Time limit:2000/1000 MS (java/others)
Memory limit:65536/65536 K (java/others)
Problem description

As we all know, Meng Meng six flower is not good at maths, so Yong too gave her some math problems to do exercises, one of which is this:
One day Yong too got a string of length n, but the six flowers accidentally lost the string. So they want to recover this string. Yong remembers that this string contains only lowercase letters and that the strings are not palindrome strings. Unfortunately, he doesn't remember some of the characters in the string, can you help him recover the string?
Of course, this question is very difficult for the six flowers, can you help her?

Enter a description

Multiple sets of data, the number of data groups not more than 20, each group of data the first row of two positive integer n. Next line a length of n contains only lowercase letters and '? ' The string, '? ' It means that Yong has forgotten the character of this position.
1≤n≤103

Output description

Each set of data output is only one line of the length of a string of n only lowercase letters, if there are a number of legal solutions, output dictionary order is minimal, if there is no solution, please output "QwQ"

Input sample

5
A?bb?
3
Aaa

Output sample

Aabba

QwQ

#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <vector> #include <map> #include < cstdlib> #include <set> #include <stack> #include <cstring>using namespace Std;template<class T    >inline T Read (t&x) {char C;    while ((C=getchar ()) <=32) if (c==eof) return 0;    BOOL Ok=false;    if (c== '-') Ok=true,c=getchar ();    for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 ';    if (OK) x=-x; return 1;} Template<class t> inline T read_ (t&x,t&y) {return read (x) &&read (y);} Template<class t> inline T read__ (t&x,t&y,t&z) {return read (x) &&read (y) &&read (z);}    Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x;    if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');}    Template<class t>inline void Writeln (T x) {write (x); Putchar (' \ n ');} //-------ZCC IO Template------const int MAXN=100001;CONST double inf=999999999; #define Lson (rt<<1), L,m#define Rson ( rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,t,n) for (int i= (t);i< (n); i++) typedef long Long LL; typedef double DB;TYPEDEF pair<int,int> P; #define BUG printf ("---\ n"); #define MOD 10007int N;char a[maxn];bool Pan (    Char *s) {for (int i=0; i<=n/2; i++) {if (A[i]!=a[n-1-i]) return true; } return false;} int B[maxn];int Main () {//#ifndef online_judge//freopen ("In.txt", "R", stdin);//#endif//Online_judge int m,i    , j,k,t;        while (read (n)) {scanf ("%s", a);        Memset (b,0,sizeof (b));        BOOL Flag=false;            for (i=0,j=0; i<n; i++) if (a[i]== '? ')                {flag=true;            B[j++]=i; } if ((!flag&&!pan (a)) | | (!pan (a) &&n%2==1&&a[n/2]== '? '        &&j==1)) {puts ("QwQ"); } else {bool ok=false;            for (i=0;i<n;i++) if (a[i]== '? ')            A[i]= ' a '; For (i=j-1, i>=0; i--) {for (char k= ' a '; k<= ' z '; k++) {A                    [B[i]]=k;                        if (Pan (a)) {ok=true;                    Break                }} if (OK) break;            Else a[b[i]]= ' a ';        } puts (a); }} return 0;}

Rikka with string bc#37

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.