#include<bits/stdc++.h>
using namespace std;
string s;
char ans[200007][7];
char anss[200007][7];
int main(){
cin>>s;
int n=s.size();
int sta=0;
int cnt=1;
int flag=0;
ans[cnt][0]=s[0];
//把字符串分割成一个字符,两个字符,一个字符,两个字符。。。
//因为前后字符数量不一样,所以肯定不相同。如果这个字符和上一个不一样,就分割成一个字符,一个字符,一个字符。。。
for(int i=1;i<n;++i){
if(s[sta]==s[i]&&flag==0){//当这个字符和前一个一样时
if(i+1<n){//如果后面还有字符,就把这两个字符放在一段
cnt++;
flag=1;
i++;
ans[cnt][0]=s[i-1];
ans[cnt][1]=s[i];
}
else if(i==1)//如果后面没有字符,就把这个字符和前一段合并,当前面没有字符时,就和上一个字符合并,此时就会少一段,例如s=aa
cnt--;
}
else if(s[sta]!=s[i]&&flag==0){
cnt++;
sta=i;
ans[cnt][0]=s[i];
}
else if(flag==1){
cnt++;
sta=i;
flag=0;
ans[cnt][0]=s[i];
}
}
cout<<cnt;
return 0;
}

Atcoder Grand Contest 037A(贪心,思维)的更多相关文章

  1. AtCoder Grand Contest 011D(思维,规律,异或)

    #include<bits/stdc++.h>using namespace std;char s[200007];int ans[200007];int main(){    int n ...

  2. AtCoder Grand Contest 019 B - Reverse and Compare【思维】

    AtCoder Grand Contest 019 B - Reverse and Compare 题意:给定字符串,可以选定任意i.j且i<=j(当然i==j时没啥卵用),然后翻转i到j的字符 ...

  3. Atcoder Grand Contest 024 E - Sequence Growing Hard(dp+思维)

    题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序 ...

  4. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  5. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  6. AtCoder Grand Contest 019 F-yes or no

    AtCoder Grand Contest 019 F-yes or no 解题思路: 考虑一个贪心策略,假设当前还有 \(x\) 道 \(\text{yes}\) 和 \(y\) 道 \(\text ...

  7. AtCoder Grand Contest 019 A: Ice Tea Store

    tourist出的题诶!想想就很高明,老年选手可能做不太动.不过A题还是按照惯例放水的. AtCoder Grand Contest 019 A: Ice Tea Store 题意:买0.25L,0. ...

  8. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  9. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

随机推荐

  1. maven设置指定jdk版本

    今天心血来潮准备折腾一下jeecg,去下载了一个maven版本的项目,既然下载了maven版的,当然就要配置好maven环境了. 因为之前简单学习过maven,当时使用的版本是3.3.9的,但是今天在 ...

  2. 查看svn 提交记录

    svn log -v -r {2019-8-11}:{2019-8-16} -l 30 | sed -n '/wangyue01/,/--$/ p'其中:-r {2018-9-10}:{2018-9- ...

  3. ST股

    一.简介: 意即“特别处理”.该政策针对的对象是出现财务状况或其他状况异常的. 1998年4月22日,沪深交易所宣布,将对财务状况或其它状况出现异常的上市公司股票交易进行特别处理(Special tr ...

  4. 页面布局 Wrap 组件 和 RaisedButton按钮

    一.RaisedButton 定义一个按钮 Flutter 中通过 RaisedButton 定义一个按钮.RaisedButton 里面有很多的参数,只讲简单的进行使用. return Raised ...

  5. netty(一)---服务端源码阅读

    NIO Select 知识 select 示例代码 : //创建 channel 并设置为非阻塞 ServerSocketChannel serverChannel = ServerSocketCha ...

  6. 【Python协程的实现】

    " 补充:数据安全问题 进程: 多个进程操作同一个文件,会出现数据不安全 线程: 多个线程操作同一个全局变量,会出现数据不安全 对于共享的数据操作: 如果是 += *= /= -= 操作,都 ...

  7. 关于iOS appIcon launchImage 尺寸

    https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix ...

  8. 安卓之滚动视图ScrollView

    (1)垂直方向滚动时,layout_width要设置为match_parent,layout_height要设置为wrap_content (2)水平方向滚动时,layout_width要设置为wra ...

  9. MySQL8.0.11安装后,使用CMD无法启动mysql服务

    首先,先把mysql的bin路径添加到系统环境变量 这样做可以,直接进入CMD后执行mysql服务,不需要进入mysql的bin文件路径去执行. 第一步:在MySQL的安装文件的bin目录(例如:C: ...

  10. 计算机二级-C语言-字符数字转化为整型数字。形参与实参类型相一致。double类型的使用。

    //函数fun功能:将a和b所指的两个字符串分别转化成面值相同的整数,并进行相加作为函数值返回,规定只含有9个以下数字字符. //重难点:字符数字转化为整型数字. #include <stdio ...