题解 | #子串计算#
子串计算
https://www.nowcoder.com/practice/bcad754c91a54994be31a239996e7c11
#include <iostream> #include "map" using namespace std; int main() { string line; while (cin >> line) { // 注意 while 处理多个 case // cout << a + b << endl; map<string, int> strMap; for (int i = 0; i <= line.size() - 1; i++) {//起点 for (int j = 1; j <= line.size() - i; j++) {//子串长度 string str = line.substr(i, j); strMap[str]++; } } for(auto it=strMap.begin();it!=strMap.end();it++){ if(it->second>=2) cout<<it->first<<' '<<it->second<<endl; } } } // 64 位输出请用 printf("%lld")