hihoCoder 1039 字符消除
2015-07-31 23:44
267 查看
<pre name="code" class="cpp">#include <iostream> #include <cstdio> #include <string> #include <vector> #include <algorithm> using namespace std; string solve(const string& str){ int ll =str.size(); if(ll <= 1) return str; vector<char> v; for(int i = 0; i < ll-1; i++){ if(str[i] == str[i+1]){ while(i+1 < ll && str[i] == str[i+1]) i++; } else v.push_back(str[i]); } if(str[ll-2] != str[ll-1]) v.push_back(str[ll-1]); return string (v.begin(),v.end()); } int main(){ int T; const string Insert="ABC"; scanf("%d",&T); while(T--){ string str,tmp; cin>>str; int l = str.size(); int maxn = l,minn = l; for(int i = 0; i < l; i++){ for(int j = 0;j < 3;j++){ tmp = str.substr(0,i+1) + Insert[j] + str.substr(i+1); int len = tmp.size(); while(len > (tmp = solve(tmp)).size()){ len = tmp.size(); } minn = min(minn,len); } } printf("%d\n",maxn - minn + 1); } return 0; }
相关文章推荐
- Aircrack-ng支持网卡列表(下)
- 云计算在企业中的应用(2)
- hd 2187
- 一步步学习操作系统(2)——在STM32上实现一个可动态加载kernel的"my-boot"
- jquery属性选择器
- 今天
- 对sql的查询语句做成对象式,简单实现。查询参数实现一
- 使用drbd结合corosync实现mysql的高可用集群服务
- 《显示数字时钟》
- 数据库系统应用一:工资管理系统系列一
- HDU - 1142 A Walk Through the Forest (DP + 最短路)
- linux 系统tty、pty和pts 的概念及区别
- 数据结构导论——泛读
- throws和throw的区别
- BGP(状态机故障)
- HttpClient详解(三)—get post封装实例
- HttpClient详解(二)—请求详解
- js对象字面量
- 自动化运维工具Ansible之Playbooks变量的使用
- 《unix环境高级编程》有关不带缓冲io--1