国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++ 字符串序列 進行長度 排序的同時,保持字典序排序

2019-11-06 06:50:42
字體:
來源:轉載
供稿:網友

elimDups實現了字典排序: unique()算法的作用是吧重復的元素放到最后并用”???”覆蓋;然后用容器erase操作來刪除后面。 stable_sort()就是在長度排序下,保持字典序。

#include <iostream>#include <algorithm>using namespace std;void elimDups(vector<string> &Words){ sort(words.begin(), words.end()); auto end_unique = unique(words.begin(),words.end()); words.erase(end_unique, words.end());}bool isShorter(const string &s1, const string &s2){ return s1.size() < s2.size();}int main() { vector<string> words = {"the","quick","red","fox","jumps","over","the","slow","red","turtle"}; elimDups(words); stable_sort(words.begin(), words.end(), isShorter); for ( const auto &s : words ) cout << s << " "; cout << endl; return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 胶南市| 宽城| 墨竹工卡县| 游戏| 桦川县| 武定县| 北宁市| 三亚市| 西乌珠穆沁旗| 通化县| 漠河县| 克东县| 略阳县| 卢氏县| 新沂市| 天峨县| 尼勒克县| 辽宁省| 洞口县| 肃南| 方城县| 西和县| 高唐县| 宝清县| 准格尔旗| 高州市| 金沙县| 青铜峡市| 额敏县| 榆中县| 长寿区| 东安县| 洛南县| 临海市| 克拉玛依市| 汕尾市| 罗山县| 扬中市| 通河县| 正镶白旗| 清水河县|