字串计算(map的使用)

 

#include <iostream>
#include <map>
using namespace std;

map <string, int> m;
int main() {

	string str;
	string sub;
	map <string, int>::iterator it;
	while (cin >> str) {
		for (int len = 1; len <= str.size() - 1; len++) {
			for (int i = 0; i <= str.size() - len; i ++) {
				sub = str.substr(i,len);
//				cout << sub << endl;
				m[sub]++;
			}
		}

		for (it = m.begin(); it != m.end(); it++) {
			if (it->second > 1) {
				cout << it->first << " " << it->second << endl;
			}

		}




	}







}
发布了123 篇原创文章 · 获赞 1 · 访问量 5445

猜你喜欢

转载自blog.csdn.net/bijingrui/article/details/104870348