HDU 5202 Rikka with string
2015-04-15 16:13
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?
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:
5
a?bb?
3
aaa
Sample Output:
aabba
QwQ
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#define LL long long
#define FOR(i, x, y) for(int i=x;i<=y;i++)
using namespace std;
const int MAXN = 1000 + 10;
char s[MAXN];
int n;
int ok;
bool check()
{
for(int i=0;i<=n/2;i++)
{
if(s[i] != s[n-1-i])
return false;
}
return true;
}
void dfs(int x)
{
if(ok)
return ;
if(x >= n)
{
if(!check())
{
printf("%s\n", s);
ok = 1;
}
return ;
}
if(s[x] >= 'a' && s[x] <= 'z')
{
dfs(x + 1);
return ;
}
else
{
for(char t = 'a'; t <= 'z'; t++)
{
s[x] = t;
dfs(x + 1);
s[x] = '?';
}
}
}
int main()
{
while(scanf("%d", &n)!=EOF)
{
scanf("%s", s);
ok = 0;
dfs(0);
if(!ok) printf("QwQ\n");
}
return 0;
}
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?
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:
5
a?bb?
3
aaa
Sample Output:
aabba
QwQ
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#define LL long long
#define FOR(i, x, y) for(int i=x;i<=y;i++)
using namespace std;
const int MAXN = 1000 + 10;
char s[MAXN];
int n;
int ok;
bool check()
{
for(int i=0;i<=n/2;i++)
{
if(s[i] != s[n-1-i])
return false;
}
return true;
}
void dfs(int x)
{
if(ok)
return ;
if(x >= n)
{
if(!check())
{
printf("%s\n", s);
ok = 1;
}
return ;
}
if(s[x] >= 'a' && s[x] <= 'z')
{
dfs(x + 1);
return ;
}
else
{
for(char t = 'a'; t <= 'z'; t++)
{
s[x] = t;
dfs(x + 1);
s[x] = '?';
}
}
}
int main()
{
while(scanf("%d", &n)!=EOF)
{
scanf("%s", s);
ok = 0;
dfs(0);
if(!ok) printf("QwQ\n");
}
return 0;
}
相关文章推荐
- HDU-5202-Rikka with string(DFS + WrongAnswer)
- hdu5202 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 5202 Rikka with string(模拟)
- 【CUGBACM15级BC第37场 A】hdu 5202 Rikka with string
- HDU 5202 Rikka with string (水DFS)
- hdu 5202 Rikka with string
- BestCoder #37 Rikka with string (hdu 5205)
- Rikka with String HDU - 6086 多校#5 AC自动机DP
- HDU 6086 Rikka with String(2017 Multi-University Training Contest 3)
- HDU 6086 Rikka with String (AC 自动机+状压 dp, 2017 Multi-Univ Training Contest 5)
- hdu 6086 Rikka with String
- Hdu-6086 Rikka with String(AC自动机+DP)
- hdu Rikka with string (dfs)