Codeforces Round #387(Div. 2)B. Mammoth's Genome Decoding【模拟】

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. 


题目大意:

给你一个长度为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");
        }
    }
}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值