-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path902.cpp
More file actions
43 lines (41 loc) · 773 Bytes
/
902.cpp
File metadata and controls
43 lines (41 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<cstring>
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
using namespace std;
int main()
{
char buf[1000000];
int n;
map<string,int> password;
map<string,int>::iterator it;
while(scanf("%d%s",&n,buf)!=EOF)
{
// cout<<n<<endl;
password.clear();
int len = strlen(buf),num=0;
char cbuf[n+1];
string ans;
for(int i=0; i <= len - n; i++)
{
strncpy(cbuf,buf+i,n);
cbuf[n] = '\0';
it = password.find(string(cbuf));
if(it != password.end())
password[string(cbuf)]++;
else
password.insert(pair<string, int>(string(cbuf),1));
}
for(it = password.begin(); it != password.end(); it++)
{
if(num < it->second)
{
ans = it->first;
num = it->second;
}
}
cout<< ans << endl;
}
return 0;
}