[ 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在中间的 ...
 
随机推荐
- 这可能是目前最新的 Vue 相关开源项目库汇总(转)
			
访问地址:https://juejin.im/entry/58bf745fa22b9d0058895a58 原文链接:https://github.com/opendigg/awesome-githu ...
 - 使用Jenkins部署Python项目
			
廖大使用Fabric部署的.我使用Jenkins试试部署过程.虽然说是用python项目部署测试的,但其他项目也是同理的. 参考Jenkins+Python部署完整版,不过安装方式不同. 安装tomc ...
 - 2018-2019-1 20165205 ch02 课下作业
			
ch02 课下作业 2.96 代码 #include <stdio.h> #include <stdlib.h> typedef unsigned float_bits; fl ...
 - 2101244 - FAQ: SAP HANA Multitenant Database Containers (MDC)
			
Symptom You face issues or have questions related to multitenant database containers in SAP HANA env ...
 - grep -A -B -C 显示抓取的前后几行参数
			
我经常用grep找东西,比如用户名和密码.大部分站点和用户名和密码都是在一样的,方便grep查找.有时,为了文本好看,我会放在多行.比如 wikipedia多个语言版本上有多个账号,就放在wikipe ...
 - Linux的Namespace与Cgroups介绍
			
Namespace 的概念 Linux Namespace 是kernel 的一个功能,它可以隔离一系列系统的资源,比如PID(Process ID),User ID, Network等等.一般看到这 ...
 - vue 时间过滤
			
1.过滤13位时间戳(以评论时间为例) filters : { formattime2: function (value) { //value为13位的时间戳 var timestamp = Date ...
 - [Solution] 973. K Closest Points to Origin
			
Difficulty: Easy Problem We have a list of points on the plane. Find the K closest points to the ori ...
 - Full authentication is required to access this resource
			
参考 https://www.jianshu.com/p/d10e0cee4adb security.basic.enabled=false
 - mybatis 根据参数映射对应模型
			
ORM 框架的优势在于能让我们利用面向对象的思维去操作数据库, hibernate 作为重量级的 ORM 框架对面向对象的支持很强大.作为半自动化的 mybatis ,对面向对象的支持也是很完备的.这 ...