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

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

#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. clientWidth、offsetWidth、scrollWidth……

    1.元素视图属性 clientWidth:元素内容可视区宽度(水平方向 width + 左右 padding). clientHeight:元素内容可视高度(垂直方向 height + 上下paddi ...

  2. linux下nginx软件的学习

    参考博客 1.nginx是什么 nginx是一个开源的,支持高性能,高并发的web服务和代理服务软件.它是开源的软件. nginx比它大哥apache性能改进许多,nginx占用的系统资源更少,支持更 ...

  3. .NET性能优化-使用ValueStringBuilder拼接字符串

    前言 这一次要和大家分享的一个Tips是在字符串拼接场景使用的,我们经常会遇到有很多短小的字符串需要拼接的场景,在这种场景下及其的不推荐使用String.Concat也就是使用+=运算符. 目前来说官 ...

  4. Linux中文件/文件系统的压缩、打包和备份总结(基于rhel7)

    文件/文件系统的压缩.打包 Linux有哪些压缩工具可供选择 按压缩比:xz>bzip2>gzip,按压缩时长:gzip>bzip2>xz,另外还有zip可以选择. gzip只 ...

  5. JavaScript 任务池

    JavaScript 任务池 本文写于 2022 年 5 月 13 日 线程池 在多线程语言中,我们通常不会随意的在需要启动线程的时候去启动,而是会选择创建一个线程池. 所谓线程池,本意其实就是(不止 ...

  6. Redis设计与实现3.1:主从复制

    主从复制 这是<Redis设计与实现>系列的文章,系列导航:Redis设计与实现笔记 SLAVEOF 新旧复制功能 旧版复制功能 旧版复制功能的实现为 同步 和 命令传播: 当刚连上Mas ...

  7. es6.4.2api

    这是讲数据库的数据导入到es里  所有用到了mysql! 1.依赖 <?xml version="1.0" encoding="UTF-8"?> & ...

  8. 监听 Markdown 文件并热更新 Next.js 页面

    Next.js 提供了 Fast-Refresh 能力,它可以为您对 React 组件所做的编辑提供即时反馈. 但是,当你通过 Markdown 文件提供网站内容时,由于 Markdown 不是 Re ...

  9. django--ORM表的多对一关系

    多对一关系是什么 Django使用django.db.models.ForeignKey定义多对一关系. ForeignKey需要一个位置参数:与该模型关联的类  class Info(models. ...

  10. 一文看完vue3的变化之处

    在通读了vue的官网文档后,我记录下了如下这些相对于2.x的变化之处. 1.创建应用实例的变化 之前一般是这样: let app = new Vue({ // ...一些选项 template: '' ...