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

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

#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. 关于数据拓展及面试题讲解 Java

    强类型语言  要求变量的使用严格符合规定,所有变量都必须先定义后才能使用 弱类型语言 Java 的数控类型分为两大类 基本类型(primitive type) 引用类型(reference type) ...

  2. 项目文章|DNA(羟)甲基化研究揭示铁离子依赖表观调控促进狼疮致病性T细胞分化|易基因

    易基因(羟)甲基化DNA免疫共沉淀测序(h)MeDIP-seq研究成果见刊<Journal of Clinical Investigation> 2022年5月2日,中南大学湘雅二医院赵明 ...

  3. 【多线程】线程创建方式三:实现callable接口

    线程创建方式三:实现callable接口 代码示例: import org.apache.commons.io.FileUtils; import java.io.File; import java. ...

  4. 817. Linked List Components - LeetCode

    Question 817. Linked List Components Solution 题目大意:给一个链表和该链表元素组成的一个子数组,求子数组在链表中组成多少个片段,每个片段中可有多个连续的元 ...

  5. CentOS下sudo的使用和sudoers配置

    一.sudo命令 sudo [参数选项] 命令 参数选项 -l:列出目前用户可执行与无法执行的指令: -v:延长密码有效期限5分钟: -u<用户>:以指定的用户作为新的身份.若不加上此参数 ...

  6. 【HEOI2014】大工程<虚树>

    虚树 我们每天都用心思索着,这究竟是为了什么呢?我想我也不知道,只是觉得如果人不思考问题就很无聊. 我觉得虚树不是什么数据结构,就是一种技巧或者工具.它能把树中\(k\)个关键点以\(O(klogk) ...

  7. ClickHouse(01)什么是ClickHouse,ClickHouse适用于什么场景

    ClickHouse的由来 ClickHouse是什么数据库?ClickHouse速度有多快?应用场景是怎么样的?ClickHouse是关系型数据库吗?ClickHouse目前是很火爆的一款面向OLA ...

  8. npm错误:Cannot find module ‘compression-webpack-plugin

    转自 (82条消息) 前端开发遇到Cannot find module 'compression-webpack-plugin'问题解决_brave_zhao的博客-CSDN博客 <div id ...

  9. CabloyJS V3.2.0支持Socket IO

    CabloyJS v3.2.0引入了Socket IO,并且实现了统一的在线推送和离线推送机制 效果演示 1. IM 用户向系统发送一条消息,系统通过websocket在线通道向用户推送一条回复 2. ...

  10. 一个全新的Vue拖拽特性实现:“移动”部分

    关于拖拽 CabloyJS提供了完备的拖拽特性,可以实现移动和调整尺寸两大类功能,这里对移动的开发进行阐述 关于调整尺寸的开发,请参见:拖拽:调整尺寸 演示 开发步骤 下面以模块test-party为 ...