747B - Mammoth's Genome Decoding - CodeForces Solution


implementation strings *900

Please click on ads to support us..

Python Code:

import sys

n = int(input())
strk = input()
new_strk = ''
amn, ost = divmod (n, 4)

amn_A = strk.count('A')
amn_C = strk.count('C')
amn_G = strk.count('G')
amn_T = strk.count('T')

if ost != 0 or amn_A > amn or amn_C > amn or amn_G > amn or amn_T > amn:
    print ('===')
    sys.exit()
    
need_A = amn - amn_A
need_C = amn - amn_C
need_G = amn - amn_G
need_T = amn - amn_T

for j in strk:
    if j != '?':
        new_strk += j
    else:
        if need_A != 0:
            new_strk += 'A'
            need_A -= 1
        elif need_C != 0:
            new_strk += 'C'
            need_C -= 1
        elif need_G != 0:
            new_strk += 'G'
            need_G -= 1
        else:
            new_strk += 'T'

print (new_strk)    

C++ Code:

#include<bits/stdc++.h>
#include<iostream>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<"\n";
#define no cout<<"NO"<<"\n";
#define counterr cout<<counter<<"\n";counter=0;
#define asort sort(arr,arr+n);
#define dsort sort(arr,arr+n,greater<int>());
#define maxind  cout<< max_element(arr, arr + n) - arr<<endl;
#define pb(data) push_back(data);
#define eraseall(v,data) v.erase(remove(v.begin(),v.end(),data),v.end());
const int mod = 1e9+7;
using namespace std;
long long t,n,m,mn=LONG_MAX,mx=LONG_MIN,counter=0,c,q,x,y,z,d,sum=0,a,b,k,counter2=0;
string s1,s2,s3,s4,s,ss;
char ch;
bool sortbysec(const pair<string,long long> &a,
              const pair<string,long long> &b)
{
    if(a.second!=b.second)
    return (a.second > b.second);
    return a.first<b.first;
}
bool prime(long long n){
    if (n<2){
        return false;
    }
for ( int i=2 ; i*i<=n ; i++){
    if (n%i==0)
        return false;
}
return true;
}
int main()
{
    fast
    map<char,int>mp;
cin>>n>>s;
m=n/4;
for ( int i=0 ; i<s.size() ; i++){
    mp[s[i]]++;
}
if ( n%4!=0 || mp['A']>m || mp['G']>m || mp['C']>m || mp['T']>m){
    cout<<"===";
} else {
for ( int i=0 ; i<s.size() ; i++){
    if (s[i]=='?'){
        if (mp['A']!=m){
            s[i]='A';
            mp['A']++;
        } else if (mp['T']!=m){
        s[i]='T';
        mp['T']++;
        } else if (mp['C']!=m){
        s[i]='C';
        mp['C']++;
        } else {
        s[i]='G';

        }
    }
}
cout<<s;
}

}


Comments

Submit
0 Comments
More Questions

22A - Second Order Statistics
1720B - Interesting Sum
1720A - Burenka Plays with Fractions
3A - Shortest path of the king
1720C - Corners
574A - Bear and Elections
352B - Jeff and Periods
1244A - Pens and Pencils
1670A - Prof Slim
1189A - Keanu Reeves
678A - Johny Likes Numbers
1699C - The Third Problem
1697D - Guess The String
754B - Ilya and tic-tac-toe game
760A - Petr and a calendar
1573A - Countdown
166A - Rank List
1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array