B. Mammoth’s Genome Decoding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
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 ‘?’.
Output
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).
Examples
Input
8
AG?C??CT
Output
AGACGTCT
Input
4
AGCT
Output
AGCT
Input
6
????G?
Output
===
Input
4
AA??
Output
===
Note
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.
~A,T,C,G,各N / 4个~如果有一开始就大于~ N / 4 或者N 不不能整除4的输出 “===”~反之都可以构造~~
AC代码:
#include<bits/stdc++.h>
using namespace std;
char st[260];
int main()
{
int N,num = 0,na = 0,ng = 0,nc = 0,nt;
scanf("%d %s",&N,st);
for(int i = 0 ; i < N; i++){
if(st[i] == '?') num++;
else if(st[i] == 'A') na++;
else if(st[i] == 'T') nt++;
else if(st[i] == 'C') nc++;
else if(st[i] == 'G') ng++;
}
int nl = N / 4;
if(N % 4 || na > nl || nt > nl || nc > nl || ng > nl) printf("===\n");
else{
for(int i = 0 ; i < N; i++)
if(st[i] == '?'){
if(na < nl) st[i] = 'A',na++;
else if(nt < nl) st[i] = 'T',nt++;
else if(nc < nl) st[i] = 'C',nc++;
else if(ng < nl) st[i] = 'G',ng++;
}
cout << st;
}
return 0;
}