[ 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在中间的 ...
随机推荐
- linux 时间和时区设置
在linux中与时间相关的文件有 /etc/localtime /etc/timezone 其中,/etc/localtime是用来描述本机时间,而 /etc/timezone是用来描述本机所属的时区 ...
- SpringData中使用@Modifying注解实现修改操作
通过@Modifying可以实现修改和删除操作 @Modifying @Query("update Person set email = :email where lastName =:la ...
- spring boot 日志介绍 以及 logback配置示例
https://www.cnblogs.com/flying607/p/7827460.html 以下是springboot的一个局部依赖关系: 可以看到,java util logging(jul) ...
- [Shell]Bash变量:自定义变量 & 环境变量 & 位置参数变量 & 预定义变量
--------------------------------------------------------------------------------- 变量是计算机内存的单元,其中存放的值 ...
- pymongo操作mongodb
此验证中只开启两个mongodb节点,可以连接任意节点,以下操作不涉及读写,不涉及连接那个节点 mongodb连接: from pymongo import MongoReplicaSetClient ...
- cdnbest如何让用户访问走最近最快的线路(分组线路)
用户访问网站有时网络有互通的问题,cdnbest的分组解析可以细分线路,让用户访问自动走最优线路,线路不细分都加默认里,访问的节点是随机分配的 下面我们讲下如何设置: 比如你有电信,移动,和国外的节点 ...
- JS实现数组去重方法总结(三种常用方法)
方法一: 双层循环,外层循环元素,内层循环时比较值 如果有相同的值则跳过,不相同则push进数组 Array.prototype.distinct = function(){ var arr = th ...
- POJ-2387.Til the Cows Come Home.(五种方法:Dijkstra + Dijkstra堆优化 + Bellman-Ford + SPFA + Floyd-Warshall)
昨天刚学习完最短路的算法,今天开始练题发现我是真的菜呀,居然能忘记邻接表是怎么写的,真的是菜的真实...... 为了弥补自己的菜,我决定这道题我就要用五种办法写出,并在Dijkstra算法堆优化中另外 ...
- [leetcode]254. Factor Combinations因式组合
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
- [leetcode]70. Climbing Stairs爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...