#include"iostream"
#include"string"
using namespace std;


pair<string,int> fun(const string& str);
int _tmain(int argc, _TCHAR* argv[])
{
	string str="abcbcbcabc";
	pair<string,int> p=fun(str);
	cout<<p.first<<": "<<p.second<<endl;
	return 0;
}

pair<string,int> fun(const string& str){
	if(str.empty())
		return make_pair("a",0);

    int count,max=0;
	string substr,st;
	for(int i=str.length();i>=1;i--)
		for(int j=0;j<str.length()-i+1;j++){
			count=0;
			st=str.substr(j,i);
			for(int k=0;k<str.length()-i+1;k++)
				if(!st.compare(str.substr(k,i)))
					count++;
			if(count>max){
				max=count;
				substr=st;
			}
      }
	return make_pair(substr,max);
}


    注意: pair的使用,元素调用为first和second



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2021-11-23
相关资源
相似解决方案