题解 | #子串计算#

子串计算

https://www.nowcoder.com/practice/bcad754c91a54994be31a239996e7c11

//土尔逊Torson 编写于2023/06/13
#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]++;                      //映射值加1
			}
		}
		map<string, int>::iterator it;              //定义迭代器
		for (it = number.begin(); it != number.end(); ++it) {
			if (1 < it->second) {
				cout << it->first << " " << it->second << endl;
			}
		}
	}
	system("pause");
	return EXIT_SUCCESS;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

爱吃烤肠的牛油最喜欢...:50K是ssp了估计,ssp的人家多厉害都不用说,每年比例大概在百分之5左右
点赞 评论 收藏
分享
阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
10-15 20:01
已编辑
上海大学 Java
钉钉什么垃圾公司,约面鸽人
光年在眼前:不是坏事,感觉钉钉挺逆天的,二面结束还给我留作业,让我使用钉钉和看最新的发布会,然后说感受,我是应该不会去,三面直接拒绝不面了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务