[ 9.29 ]CF每日一题系列—— 765B字符串规律
Description:
遇到了ogo可以变成***如果ogo后面有go统统忽略,输出结果
Solution:
哎如果我一开始对题意的解读如上的话,就不会被整的那么麻烦了
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 150;
/***找到一个题目的规律,做题的方法是多么的重要!!***/
/***以后没有好的方法,不打代码***/
char s[maxn];
int main()
{
int len;
while(~scanf("%d%s",&len,s))
{
for(int i = 0;i < len;)
{
if(s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o')
{
printf("***");
i += 3;
while(s[i] == 'g' && s[i+1] == 'o')
{
i += 2;
}
}
else
{
printf("%c",s[i]);
i++;
}
}
printf("\n");
}
return 0;
}
看看我的超级麻烦bug多多的模拟!!!
一开始真的读错题了!
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std;
const int maxn = 1e3;
char s[maxn];
char out[maxn];
char cmp[200] = "ogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo";
int main()
{
int len;
while(~scanf("%d",&len))
{
scanf("%s",s);
int mpid = 0;
int outsid = 0;
for(int i = 0;i < len;++i)
{
out[outsid++] = s[i];
if(s[i] == cmp[mpid])
{
//printf(" %d\n",mpid);
mpid++;
}
else
{
//cout<<mpid<<endl;
if(mpid == 1)
{
outsid -= 1;
i -= 1;
}
else if(mpid == 2)
{
mpid = 0;
}
else if(mpid % 2 == 1)
{
outsid -= mpid + 1;
out[outsid++] = '*';
out[outsid++] = '*';
out[outsid++] = '*';
i--;
}
else if(mpid % 2 == 0 && mpid != 0)
{
outsid -= mpid + 1;
out[outsid++] = '*';
out[outsid++] = '*';
out[outsid++] = '*';
out[outsid++] = 'g';
out[outsid++] = s[i];
}
mpid = 0;
}
}
if(mpid > 2)
{
if(mpid % 2 == 1)
{
outsid -= mpid;
out[outsid++] = '*';
out[outsid++] = '*';
out[outsid++] = '*';
}
else if(mpid % 2 == 0)
{
outsid -= mpid;
out[outsid++] = '*';
out[outsid++] = '*';
out[outsid++] = '*';
out[outsid++] = 'g';
}
}
out[outsid] = '\0';
printf("%s\n",out);
}
return 0;
}
[ 9.29 ]CF每日一题系列—— 765B字符串规律的更多相关文章
- [ 9.24 ]CF每日一题系列—— 468A构造递推
Description: 1 - n个数问你能否经过加减乘除这些运算n -1次的操作得到24 Solutrion: 一开始想暴力递推,发现n的范围太大直接否决,也否决了我的跑dfs,后来就像肯定有个递 ...
- [ 9.9 ]CF每日一题系列—— 259A黑白棋盘检查问题
http://codeforces.com/problemset/problem/259/A PS9.8日做了但是忘了发博客,所以坚持3天了呦~ 终于读懂了这个题了,心累 Describe: 给你8 ...
- [ 10.08 ]CF每日一题系列—— 602B
Description: 一个数组,保证相邻两个元素值得差小于1,问题,最大值和最小值的差 < 1的区间长度最长是多少 Solution: 还是卡了一下,本来以为是模拟就好了,但是卡时间,想来想 ...
- [ 10.05 ]CF每日一题系列—— 962B贪心和思维?
Description: 非 * 号的地方可以放A或B,不能AA或BB,一共有a个A,b个B,问你最多放几个 Solution: 1.模拟一下,找连续空位长度,如果长度为奇数,则我可以有一个位置放任意 ...
- [ 10.4 ]CF每日一题系列—— 486C
Description: 给你一个指针,可以左右移动,指向的小写字母可以,改变,但都是有花费的a - b 和 a - z花费1,指针移动也要花费,一个单位花费1,问你把当前字符串变成回文串的最小化费是 ...
- [ 10.03 ]CF每日一题系列—— 534B贪心
Descripe: 贪心,贪在哪里呢…… 给你初始速度,结尾速度,行驶秒数,每秒速度可变化的范围,问你行驶秒数内最远可以行驶多少距离 Solution: 贪心,我是否加速,就是看剩下的时间能不能减到原 ...
- [ 9.28 ]CF每日一题系列—— 940A规律构造
Description: 输入a,b,x,给你a个0,b个1,你要给出一个组合,让这个组合里存在x位,使得这x为和其x+1位不相等 Solution: 因为肯定有一个正确的答案,所以钻了一下空子,贪心 ...
- [ 9.26 ]CF每日一题系列—— 771B递推问题
Description: 给定你命名的规律,1-10个字符,开头必须大写,最多有50个名字,然后告诉你有n个人,判断区间长度为k,那么你将得到n - k + 1个答案(YES or NO) 表示1 - ...
- [ 9.22 ]CF每日一题系列—— 484A Bits
Description: 给你一个l,r的区间让你找一个最小的x并且其二进制数要包含最多的1位,输出它的十进制 Solution: 我本来就是贪心,但是贪大了,想1一直往上添加1,但是忘记了0在中间的 ...
随机推荐
- scrapy-logging
import logging logger = logging.getLogger(__name__) # 当前文件位置 logger.warning('haha') # debug info 201 ...
- RF:操作笔记
1.变量运算
- 61.纯 CSS 创作一只咖啡壶(这个不好看)
原文地址:https://segmentfault.com/a/1190000015376202 感想: 好像不像呀,啊啊啊.伪元素.定位.动画.width和height包括内边距|边框|内容区. H ...
- Linux环境变量设置/etc/profile、/etc/bashrc、~/.profile、~/.bashrc区别
登入系统读取步骤: 当登入系统时候获得一个shell进程时,其读取环境设定档有三步 : 1.首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如 /etc/p ...
- python_06 函数、全局变量与局部变量、函数递归
函数 1.函数的定义: def 函数名(参数): #解释函数的功能 代码块 返回值 函数的定义主要有如下要点: def:表示函数的关键字 函数名:函数的名称,日后根据函数名调用函数 函数体:函数中进行 ...
- JEECG 上传插件升级-代码生成器
前言: 现有的uploadify上传是基于swf的,随着H5的普及,flash即将退出历史舞台,JEECG本着与时俱进的原则,将全面升级JEECG系统中的上传功能,采用新式上传插件plupload,此 ...
- js 模拟css3 动画1
<html> <head> <title> javaScript缓动入门 </title> </head> <body> < ...
- Rocket MQ 1 - 用
参考 http://www.iocoder.cn/categories/RocketMQ/ ; https://www.jianshu.com/nb/16219849 首先上启动方法,分别启动name ...
- @ResponseBody 与 response.getWriter.write
@responseBody注解的使用 1. @responseBody注解的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通 ...
- synchronized 和reentrantlock的优缺点
reentrantlock的优点 可以添加多个检控条件, 如果使用synchronized,则只能使用一个. 使用 reentrant locks 可以有多个wait()/notify() 队列. [ ...