最长不重复子串:输入一个字符串(‘0’-’9’,’a’-’z’,’A’-’Z’),判断字符串内最长的一个不重复子串的长度

1.最长不重复子串:输入一个字符串(‘0’-’9’,’a’-’z’,’A’-’Z’),判断字符串内最长的一个不重复子串的长度。如,aabdcadefg,最长不重复子串为6.

#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<char> tamp;
    vector<char> max_lenth;
    string str;
    cin>>str;
    vector<char>::iterator it;
    for(int i=0;i<str.length();i++){
        for(int j=i;j<str.length();j++){
//                cout<<"我在"<<endl;
//                cout<<str[j]<<endl;
            if(find(tamp.begin(),tamp.end(),str[j])==tamp.end()) {
                tamp.push_back(str[j]);
                if(tamp.size()>max_lenth.size()){
                    max_lenth.clear();
                    max_lenth.assign(tamp.begin(),tamp.end());
//                    for(it=max_lenth.begin();it!=max_lenth.end();it++){
//                        cout<<*it<<" ";
//                    }

                }
            }//tamp.push_back(str[j]);
            else{
                tamp.clear();
                break;
            }
        }
    }
    cout<<"最长的长度为:"<<max_lenth.size()<<endl;
    for(it=max_lenth.begin();it!=max_lenth.end();it++){
        cout<<*it<<" ";
    }
    cout<<endl;
    return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值