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

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

華為OJ:字串的連接最長(zhǎng)路徑查找

2019-11-08 02:15:39
字體:
供稿:網(wǎng)友

題目描述 給定n個(gè)字符串,請(qǐng)對(duì)n個(gè)字符串按照字典序排列。 輸入描述: 輸入第一行為一個(gè)正整數(shù)n(1≤n≤1000),下面n行為n個(gè)字符串(字符串長(zhǎng)度≤100),字符串中只含有大小寫字母。

輸出描述: 數(shù)據(jù)輸出n行,輸出結(jié)果為按照字典序排列的字符串。 (注意:元素可以重復(fù))

輸入例子: 9 cap to cat card two too up boat boot

輸出例子: boat boot cap card cat to too two up

解答:#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;int main(){ string str; int n; vector<string>v; while(cin>>n) { v.clear(); while(n>=1) { getline(cin,str); v.push_back(str); --n; } getline(cin,str); v.push_back(str); vector<string>::iterator it1=v.begin(); ++it1; sort(it1,v.end()); vector<string>::iterator it=v.begin(); ++it; for(;it!=v.end();it++) { cout<<*it<<endl; } } return 0;}解法二://當(dāng)元素加入set中后,已經(jīng)排好序#include <iostream>#include <string>#include <set>using namespace std;int main(){ string s; multiset<string> sset; int n; cin >> n; while (n-- && cin >> s) sset.insert(s); for (auto &t : sset) cout << t << endl; return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 象山县| 江北区| 深圳市| 扶绥县| 衡阳市| 昌图县| 正镶白旗| 梅河口市| 鄯善县| 海南省| 桐庐县| 利津县| 琼海市| 虞城县| 海阳市| 大连市| 临漳县| 雅江县| 郸城县| 沁水县| 盐城市| 皋兰县| 铜梁县| 固安县| 富源县| 罗江县| 红河县| 长岭县| 揭西县| 河曲县| 江陵县| 漳浦县| 句容市| 山阳县| 尉氏县| 泌阳县| 安阳县| 九龙城区| 尖扎县| 白城市| 肇州县|