-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy path10.9.cpp
More file actions
33 lines (30 loc) · 857 Bytes
/
10.9.cpp
File metadata and controls
33 lines (30 loc) · 857 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
/*
* 题目名称:子串计算
* 题目来源:北京大学复试上机题
* 题目链接:http://t.cn/AiCuJtI5
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
int main() {
string str;
while (cin >> str) {
map<string, int> number;
for (int i = 0; i <= str.size(); ++i) {
for (int j = 0; j < i; ++j) {
string key = str.substr(j, i - j); //每个子串
number[key]++;
}
}
map<string, int>::iterator it; //定义迭代器
for (it = number.begin(); it != number.end(); ++it) {
if (1 < it->second) {
cout << it->first << " " << it->second << endl;
}
}
}
return 0;
}