-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasswordSearch_UVA902.cpp
51 lines (43 loc) · 1021 Bytes
/
passwordSearch_UVA902.cpp
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
44
45
46
47
48
49
50
51
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("passwordSearch_UVA902.in");
ofstream fout("passwordSearch_UVA902.out");
int main()
{
while (true)
{
int n = 0;
fin >> n;
if (n == 0) break;
string text; fin >> text;
int size = text.size(), ans_max = 0;
string ans = "hi";
map<string, int> file;
for (int i = 0; i + n - 1 <= size - 1; ++i)
{
string temp = "";
for (int j = i; j <= i + n - 1; ++j)
{
temp += text[j];
}
++file[temp];
if (ans_max < file[temp])
{
ans_max = file[temp];
ans = temp;
}
}
fout << ans << '\n';
}
return 0;
}