[ 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-items
items定义字段名字 import scrapy class HrItem(scrapy.Item): # define the fields for your item here like: ti ...
- matlab-画一个圆
我们可以用 李萨如图形 的思路去画一个圆,或者一个椭圆. x,y是圆心所在坐标,r是半径,nseg是边缘段数(越高,边缘越顺滑,建议100以上),S是plot的样式设置字符 function Draw ...
- SpringBoot 之 MVC
SpringBoot MVC 和静态资源 首先,我们一定要搞清楚,mvc 配置和 static 配置的联系和区别. mvc 配置其实就是给 spring mvc 框架用的, 具体来说, 比如 @Req ...
- leetcode5
public class Solution { private int lo, maxLen; public String LongestPalindrome(String s) { int len ...
- Innodb锁相关总结
一.InnoDB共有七种类型的锁: (1)共享/排它锁(Shared and Exclusive Locks) (2)意向锁(Intention Locks) (3)插入意向锁(Insert Inte ...
- k8s之创建etcd集群
主机规划 maste01——192.168.10.63 master02——192.168.10.64 node01——192.168.10.65 node02——192.168.10.66 1.为保 ...
- Shiro Remember me设置
1. 在Spring的相关配置文件中加入如下Remember me管理器配置: <!-- rememberMe管理器 --> <bean id="rememberMeMan ...
- JAVA获取系统信息以及系统时间
在做测试的时候,经常需要获取系统信息,并且用获取到的系统时间给生成的报告取名字. 以下代码实在TestNG展示的,没有Test NG的话需要些一个main方法. import java.net.Ine ...
- [leetcode]33. Search in Rotated Sorted Array旋转过有序数组里找目标值
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- LinkedList 源码实现
闲暇之余,准备将Java 一些常用的数据结构进行重新的剖析,并记录博客比如LinkedList ,HashMap ,HashTable ,以及并发包所引入的集合,在博客中会陆续更新 start 哈哈, ...