Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
| discuss902 - | Accepted | C++11 | 0.790 | 0.030 | 1349 | 8 mins ago |
Problem: 902
Suggest:
- Use data struct unordered_map<string, int> to save frequense of string have length is n
#include<bits/stdc++.h>
using namespace std;
int n;
string s, st;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
while(cin >> n >> s){
unordered_map<string, int> cnt;
for(int i=0; s[i]; i++){
try{
st=s.substr(i, n);
cnt[st]++;
}
catch(...){
break;
}
}
int maxx= -1000111000;
for(auto it=cnt.begin(); it!=cnt.end(); it++)
maxx= max(maxx, it->second);
for(int i=0; s[i]; i++){
try{
st=s.substr(i, n);
if (cnt[st]==maxx){
cout<<st<<"\n";
break;
}
}
catch(...){
break;
}
}
}
}
No comments:
Post a Comment