B串串香 求大佬看看为什么WA
#include<bits/stdc++.h> using namespace std; int main() { int n; string s; cin>>n; cin>>s; int i,j; string ss; map<string,int>m; if(n==1){ cout<<s; } else{ for(i=0;i<s.size()-1;i++){ for(j=i+1;j<s.size();j++){ ss=s.substr(i,j-i+1); m[ss]++; } } //记录每一个字串的出现次数 string ans; int maxx=0; for(const auto& a : m){ if(maxx<a.second){ maxx=a.second; ans=a.first; } } //找到出现次数最多的字串 cout<<ans; } return 0; }
和其他佬发的题解对照了一下觉得思路应该没错才对 oTATo