CodeForces-747B
在两种情况下不能得到答案:1、n不是4的整数倍 2、某个字符的数量大于n/4
如果满足上述条件直接打印“===”,否则填充数组。
AC代码:
#include<cstdio>
#include<cstring>
const int maxn=255+5;
char s[maxn],cnt[4];
const char ch[]={'A','C','G','T'};
int main(){
int n;
while(scanf("%d",&n)!=EOF){
memset(cnt,0,sizeof(cnt));
scanf("%s",s);
if(n%4!=0) {
printf("===\n");
continue;
}
for(int i=0;i<n;++i){
if(s[i]=='A') cnt[0]++;
else if(s[i]=='C') cnt[1]++;
else if(s[i]=='G') cnt[2]++;
else if(s[i]=='T') cnt[3]++;
}
int flag=1;
for(int i=0;i<4;++i)
if(cnt[i]>n/4) {
printf("===\n");
flag=0;
break;
}
if(!flag) continue;
for(int i=0;i<n;++i){
if(s[i]!='?') continue;
for(int j=0;j<4;++j){
if(cnt[j]<n/4) {
++cnt[j];
s[i]=ch[j];
break;
}
}
}
printf("%s\n",s);
}
return 0;
}
如有不当之处欢迎指出!
CodeForces-747B的更多相关文章
- 【58.33%】【codeforces 747B】Mammoth's Genome Decoding
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- 汉诺塔python3函数编写和过程分析
!/usr/bin/env python3 -- coding: utf-8 -- 利用递归函数计算阶乘 N! = 1 * 2 * 3 * ... * N def fact(n): if n == 1 ...
- Zabbix系统数据采集方法总结
转:http://www.blog.chinaunix.net/uid-9411004-id-4115731.html 老文章,直接拿来用了,官网也有最新分类,没高兴翻译 在Zabbix系统中有多达十 ...
- htmlcss渐变及兼容性
自我总结,欢饮拍砖. <!DOCTYPE HTML> <html lang="en"> <head> <meta content ...
- Ajax异步信息抓取方式
淘女郎模特信息抓取教程 源码地址: cnsimo/mmtao 网址:https://0x9.me/xrh6z 判断一个页面是不是Ajax加载的方法: 查看网页源代码,查找网页中加载的数据信息,如果 ...
- Call to undefined function mysql_connect()错误原因
从PHP5.0开始就不推荐使用mysql_connect()函数,到了php7.0则直接废弃了该函数,替代的函数是: mysqli_connect();
- Linux 虚拟机忘记root密码
Linux 虚拟机忘记root密码可以按照下面的步骤重新设置密码: 1.在grub界面,也就是有press any key的那个界面,按下任意键 2.键入e,出现三行文字,按上下键选择kernel那一 ...
- BZOJ 2754: [SCOI2012]喵星球上的点名 [AC自动机+map+暴力]
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1902 Solved: 837[Submit][St ...
- H5动画
1.参考:http://blog.csdn.net/whqet/article/details/42911059?readlog https://developer.mozilla.org/zh-CN ...
- idea Code激活
参考:http://blog.csdn.net/gnail_oug/article/details/70677272 1.将激活包复制到bin安装目录: 2.在安装的idea下面的bin目录下面有2个 ...
- servlet上传与下载
上传页面 上传学生信息 学号 姓名 密码 性别 男 女 年龄 身高 学院 计算机学院 软件学院 照片 简历 <!DOCTYPE html> <html lang=&qu ...