hihoCoder 1039 字符消除
来源:互联网 发布:php 手动gc 编辑:程序博客网 时间:2024/04/30 03:11
<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;}
0 0
- hihoCoder:#1039 字符消除
- HihoCoder#1039:字符消除
- hihocoder #1039 : 字符消除
- hihoCoder 1039 字符消除
- hihoCoder 1039 字符消除
- #hihocoder #1039 字符消除
- hihocoder#1039 : 字符消除
- hihocoder #1039 : 字符消除
- hihocoder 1039 字符消除
- Hihocoder 1039 : 字符消除
- hihoCoder #1039 : 字符消除
- hihoCoder 1039 字符消除
- hihoCoder #1039 : 字符消除
- hihocoder #1039 : 字符消除
- hihoCoder--1039 字符消除
- [HihoCoder]#1039 : 字符消除
- hihocoder #1039 : 字符消除
- 【hihoCoder】#1039 : 字符消除
- throws和throw的区别
- HDU - 1142 A Walk Through the Forest (DP + 最短路)
- hd 2187
- Android 从源码角度分析事件分发机制(三)
- Ionic中的$ionicModal使用方法
- hihoCoder 1039 字符消除
- hdu 5336 XYZ and Drops 【BFS模拟】
- 转:OpenJDK和SunJDK的区别和联系
- Aircrack-ng支持网卡列表(下)
- kernel中常用数据结构之链表
- Ubuntu学习笔记
- 顺序表应用举例
- (转载)Objective-c的@property 详解
- hihoCoder 1044 状态压缩·一