String reduction
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1360   Accepted: 447

Description

There is a string of characters 'a' and 'b' with the length of no more than 255 characters. You can perform the substring reduction on the initial string in the following way: a substring "a*a" or "b*b" (where * (asterisk) denotes any character) can be reduces to a substring "*".

The task is to achieve a string of minimal possible length after several substring reductions.

Input

The input contains the initial string.

Output

The output contains a single line with the minimal possible length.

Sample Input

aab

Sample Output

3

Source

Northeastern Europe 2001, Western Subregion
题意:在一个串中形如a*a 或b*b可以变换为a或b,问变换之后最短长度。

由于a*a, b*b之类的字符可以匹配任意字符,那么我们只要从前

向后扫描,如果有相隔的两个字符相同,由于这三个字符能够匹配a,b任意字符,那么我们就可以让这种匹配一直进行

下去,从而将字符串不断的reduction ,只要注意字符串长度的奇偶性就可以了,如此我们可以得到一个很简单的方法

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue> using namespace std; #define N 1100
#define INF 0xfffffff
#define eps 1e-8 int main()
{
char str[N]; scanf("%s", str);
int ans, len;
len = ans = strlen(str); for(int i = ; i + < len; i++)
{
if(str[i] == str[i+])
{
if(len % )
ans = ;
else
ans = ;
}
}
printf("%d\n", ans);
return ;
}

最新文章

  1. vue.js 第五课
  2. Powershell 十个常见任务
  3. ORA-27101 ORACLE not available
  4. javascript练习-扑克牌
  5. Hive性能优化
  6. Go语言实现HashSet
  7. 杭电1097-A hard puzzle
  8. 微博输入相关js 代码
  9. oracle 随笔
  10. python3.6+linux服务器+django1.11连接MYSQL数据库
  11. JavaScript学习之自动轮播图片
  12. [原]Webpack 3 + AngularJS1.* + Bootstrap 4 + Mapbox-gl
  13. luogu P3704 [SDOI2017]数字表格
  14. 4 Django应用 第3部分(视图部分)
  15. 【WEB2.0】 网页调用QQ聊天(PC+M站)
  16. javascript原生bind方法详解
  17. fscanf和feof的组合使用
  18. 配置Linux接收H3C路由器日志
  19. Linux 多台虚拟机进行同步时间
  20. docker 部署 笔记

热门文章

  1. VS2012下自定义打开文件对话框
  2. 【ABAP系列】SAP ABAP中将字符格式的金额转换为数值的函数
  3. 如何给vue 日期控件赋值
  4. 使用SqlBulkCopy 批量操作大量数据
  5. Java相关面试题总结+答案(八)
  6. Java 动态代理及AOP实现机制
  7. [Python3 填坑] 017 实例方法、静态方法、类方法的区别
  8. [Python3 练习] 007 简单的猜数字小游戏
  9. Vue源码解读之Dep,Observer和Watcher
  10. Spring boot集成Swagger,并配置多个扫描路径