给定一个字符串,每天可以记忆三个字符,求书写出整个字符串的天数。

每次确定要记忆的三个字母,并向后寻找,若有非三个字母其中一个,则重新开启一天记忆三个字母。

#include<cstdio>
#include<iostream>
using namespace std;
int t;
string s;
int main(){
scanf("%d",&t);
while(t--){
cin>>s;
char a='0',b='0',c='0';//记忆三个字母
bool f1=false,f2=false,f3=false;//三个字母是否有值
int ans=1;//刚开始天数为1
for(int i=0;i<s.size();i++){
if(f1&&f2&&f3){
if(s[i]!=a&&s[i]!=b&&s[i]!=c){//如果是未记忆,重新开启一轮
f1=false;
f2=false;
f3=false;//恢复状态
ans++;//天数+1
a='0';
b='0';
c='0';
}
else continue;
}
if(!f1&&s[i]!=b&&s[i]!=c){//寻找需记忆的三个字母
a=s[i];
f1=true;
continue;
}
if(!f2&&s[i]!=a&&s[i]!=c){
b=s[i];
f2=true;
continue;
}
if(!f3&&s[i]!=a&&s[i]!=b){
c=s[i];
f3=true;
continue;
}
}
printf("%d\n",ans);
}
return 0;
}

CF1702B Polycarp Writes a Srting from Memory 题解的更多相关文章

  1. Codeforces Round #479 (Div. 3)题解

    CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...

  2. 工作于内存和文件之间的页缓存, Page Cache, the Affair Between Memory and Files

    原文作者:Gustavo Duarte 原文地址:http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait ...

  3. Page Cache, the Affair Between Memory and Files

    Previously we looked at how the kernel manages virtual memory for a user process, but files and I/O ...

  4. PatentTips - Reducing Write Amplification in a Flash Memory

    BACKGROUND OF THE INVENTION Conventional NAND Flash memories move data in the background to write ov ...

  5. 【并行计算-CUDA开发】CUDA bank conflict in shared memory

    http://hi.baidu.com/pengkuny/item/c8070b388d75d481b611db7a 以前以为 shared memory 是一个万能的 L1 cache,速度很快,只 ...

  6. 【Codeforces】CF Round #592 (Div. 2) - 题解

    Problem - A Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) prac ...

  7. Codeforces 997D(STL+排序)

    D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes ...

  8. Codeforces Round #479 (Div. 3)

    手速场2333,这群人贼牛逼!手速贼快!   A. Wrong Subtraction time limit per test 1 second memory limit per test 256 m ...

  9. Fedora 24中的日志管理

    Introduction Log files are files that contain messages about the system, including the kernel, servi ...

随机推荐

  1. 前端面试 -HTTP系列

    http和https 的区别? 端口 经济 安全性 响应速度 http 80端口 不需要 明文传输,安全性差 页面响应速度快,使用tcp的3次握手 https 443端口 费钱SSL需要ca 证书 S ...

  2. css实现气泡提示框三角及css中drop-shadow的使用

    css 做一个弹出气泡,样式怎么设计? 难点: 要实现白色三角型,可以在伪元素before和after上设置一个黑.一个白三角形,白三角形会挡住黑的,从而实现. &::before, & ...

  3. Python生成GIF动态图

    python生成摸头GIF 本篇教程演示了如何使用python的PIL库生成GIF图片 源码已经贴在文中,自行取用 效果演示 运行代码,会让你选择要制作的图片 运行完成后,会在同路径下生成dem.gi ...

  4. socket模块和黏包问题

    socket套接字简介 编写cs架构的程序 实现数据交互 OSI七层相当复杂 socket套接字是一门技术 socket模块>>>:提供了快捷方式 不需要自己处理每一层 " ...

  5. Ajax前后端交互——后端接收前端页面变量

    核心代码: app.py from flask import Flask, render_template, request, jsonify app = Flask(__name__) @app.r ...

  6. freeswitch使用mod_shout模块播放mp3

    概述 freeswitch 在对VOIP语音通话中,可以通过playback命令播放IVR语音文件. 默认情况下,freeswitch支持wav文件,也可以直接播放VOIP中常见编解码的G711文件. ...

  7. ES6 Promise 的链式调用

    1.什么是Promise Promise 对象代表了未来将要发生的事件,用来传递异步操作的消息. 2.对象的状态不受外界影响.Promise 对象代表一个异步操作,有三种状态: pending: 初始 ...

  8. Primal_Dual 原始对偶

    不是费用流都需要用 SPFA 吗. 众所周知,SPFA 去世了,然后网络流显然有负边.于是我们可以像 Johnson 全源最短路一样,给边加上势能,具体实现看我之前的 博客 啦. 然后对于每一次跑 D ...

  9. Codeforces Round #793 (Div. 2)

    C. LIS or Reverse LIS? D. Circular Spanning Tree E. Unordered Swaps F MCMF?

  10. plt.figure()的使用,plt.plot(),plt.subplot(),plt.subplots()和图中图

    参考:https://blog.csdn.net/m0_37362454/article/details/81511427 matplotlib官方文档:https://matplotlib.org/ ...