hihocoder 字符消除
来源:互联网 发布:linux解压gz文件命令 编辑:程序博客网 时间:2024/06/05 10:57
C++中#include<string>与#include<string.h>的区别
1. 消除重字,熟悉string类操作
#include<iostream>
#include<iostream>
#include<string>
using namespace std;
string delestr(string s){
string sc;
for(int j=0;j<s.length()-1;j++){
if(s[j]!=s[j+1]){
if(j==0||s[j]!=s[j-1]){
sc+=s[j];
}
}
}
if(s[s.length()-2]!=s[s.length()-1]){
sc+=s[s.length()-1];
}
if(sc!=s && sc.length()>1){
sc=delestr(sc);
}
return sc;
}
int main(){
int strnum;
int Max[100];
int maxscore=0,score;
cin>>strnum;
for(int i=0;i<strnum;i++){
string s,t,scopy;
cin>>s;
//while(cin>>s){
for(int k=0;k<s.length()+1;k++){
for(int m=0;m<3;m++){
t=s.substr(0,k);
t+=('A'+m);
t+=s.substr(k,s.length()-k);
scopy=delestr(t);
score=s.length()-scopy.length()+1;
maxscore=(score>maxscore)?score:maxscore;
}
}
Max[i]=maxscore;
maxscore=0;
//}
}
for(int w=0;w<strnum;w++)
cout<<Max[w]<<endl;
system("pause");
return 0;
}
阅读全文
1 0
- hihoCoder:#1039 字符消除
- HihoCoder#1039:字符消除
- hihocoder #1039 : 字符消除
- hihoCoder 字符消除
- 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 : 字符消除
- Error UNKNOWN_MEMBER_ID occurred while committing offsets for group ***
- binder 1 kernel开篇
- ubuntu 16.10 安装 openjdk 7
- Java 链式调用
- socket服务器
- hihocoder 字符消除
- AES加密解密
- Java学习笔记---反射
- Android-times-square自定义样式
- Python-时间处理
- 如何免费使用webstorm
- junit的错误 No tests found matching [{ExactMatcher:fDisplayName=test2],
- RMI远程服务操作
- Jsonp实现跨域详解