The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome.
The second line contains the string s of length n — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
8 AG?C??CT
AGACGTCT
4 AGCT
AGCT
6 ????G?
===
4 AA??
===
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom.
题目大意:
给你一个长度为n的字符串,让我们在?填入A/C/G/T,使得最终的字符串中,A/C/G/T的数量都是一样的。
如果多解,输出一个即可,如果无解,输出===
思路:
1、若想A/C/G/T的数量都一样,那么很明显,我们n/4就是各个字符需要出现的次数。
2、那么我们统计原字符串中各个字符都出现了多少次,然后对应在?处,对于未达到n/4这个数量的字符进行填补。
3、那么最后如果我们有?没有填上,或者是最终结果中,有不等于n/4的字符存在,那么就是无解的情况,否则输出答案即可。
Ac代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int vis[5];
char a[5000];
int main()
{
int n;
while(~scanf("%d",&n))
{
int sum=n/4;
memset(vis,0,sizeof(vis));
scanf("%s",a);
for(int i=0;i<n;i++)
{
if(a[i]=='A')vis[0]++;
if(a[i]=='G')vis[1]++;
if(a[i]=='C')vis[2]++;
if(a[i]=='T')vis[3]++;
}
for(int i=0;i<n;i++)
{
if(a[i]=='?')
{
for(int j=0;j<4;j++)
{
if(vis[j]<sum)
{
if(j==0)a[i]='A';
if(j==1)a[i]='G';
if(j==2)a[i]='C';
if(j==3)a[i]='T';
vis[j]++;
break;
}
}
}
}
int flag=0;
for(int i=0;i<4;i++)
{
if(vis[i]==sum)continue;
else flag=1;
}
for(int i=0;i<n;i++)
{
if(a[i]=='?')flag=1;
}
if(flag==1)
{
printf("===\n");
}
else
{
for(int i=0;i<n;i++)
{
printf("%c",a[i]);
}
printf("\n");
}
}
}