返回信息流一个字符串,求所有长度不大于3的子串出现的次数,按出现次数多少排序,出现次数相同时按字典序排序。vector <pair<string,int> > srt3Grem(const string s);
例如 s="aabcab"
输出:
a 3
ab 2
b 2
aa 1
aab 1
abc 1
bc 1
bca 1
c 1
ca 1
cab 1
这是一条镜像帖。来源:北邮人论坛 / cpp / #83736同步于 2014/10/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
求一个C++笔试题思路
behappy
2014/10/27镜像同步7 回复
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
declare:
use Map<string,int> to store the substr-count pair,
start:
loop to get all substr with length 1,
loop to get all substr with length 2,
loop to get all substr with length 3,
move all of the pairs in map to vector<string,int> via move iterator,
stable_sort(vec.begin(), vec.end(), compare_second_of_the_pair() )
搞定了,谢谢
【 在 qq86573255 的大作中提到: 】
: declare:
: use Map<string,int> to store the substr-count pair,
: start:
: ...................