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, sis 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 geno
题意:‘A’‘T’‘G’‘C’四种核苷酸,根据什么玩意法则,至少出现一次,并且每个数量相等。‘?’代表不确定的核苷酸,求'?'代表的什么核苷酸,每种核苷酸出现的位置不确定,随意出现。
分析:一开始先计算出每种核苷酸的数量和‘?’的数量,直接n/4得出每个核苷酸应该有的数量,不够的用‘?’替,这里要注意几个条件的判断,n一定输4的整数倍,否则救输出===;‘?’的数量为0的时候也要独立输出,也要判断每个核苷酸的数量<=n/4否则===;最后把‘?’替换。
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int main()
{
int n;
char aa[1001];
cin>>n;
if(n%4!=0||n<4)
{
printf("===\n");
return 0;
}
else
{
int a=0,g=0,t=0,c=0,sum=0;
scanf("%s",&aa);
for(int i=0; i<n; i++)
{
if(aa[i]=='A')
a++;
else if(aa[i]=='T')
t++;
else if(aa[i]=='G')
g++;
else if(aa[i]=='C')
c++;
else
sum++;
}
int num=n/4;
if(sum==0&&a<=num&&c<=num&&g<=num&&t<=num&&a>0&&c>0&&g>0&&t>0)
{
printf("%s\n",aa);
return 0;
}
if(a>num||g>num||t>num||c>num)
printf("===\n");
else
{
for(int i=0; i<n; i++)
{
if(aa[i]!='?')
printf("%c",aa[i]);
else
{
if(a<num)
{
printf("A");
a++;
continue;
}
if(t<num)
{
printf("T");
t++;
continue;
}
if(g<num)
{
printf("G");
g++;
continue;
}
if(c<num)
{
printf("C");
c++;
continue;
}
}
}
}
printf("\n");
}
}