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

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

PAT A 1038 Recover the Smallest Number (30)

2019-11-08 20:05:09
字體:
供稿:網(wǎng)友

經(jīng)典題目,給N個數(shù),重新順序,首尾相接,讓組成的新數(shù)最小. 按相連的大小順序排序.注意輸出0的情況

#include <bits/stdc++.h>using namespace std;bool cmp(string a, string b){ return a + b < b + a;}int main(){ int N; cin >> N; vector<string> a; for (int i = 0; i < N; i++) { string x; cin >> x; a.push_back(x); } sort(a.begin(), a.end(), cmp); string ans; for (auto e : a) ans += e; int i = 0; while (ans[i] == '0' && i < ans.size()) i++; if (i == ans.size()) cout << '0'; else for (;i < ans.size(); i++) cout << ans[i]; cout << endl;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 喀喇沁旗| 天峨县| 西贡区| 南京市| 长乐市| 交城县| 从江县| 原阳县| 湟中县| 三亚市| 临漳县| 霍林郭勒市| 新营市| 桦甸市| 长治县| 和田县| 双牌县| 仙居县| 尚义县| 泸溪县| 肃南| 通山县| 扎赉特旗| 中阳县| 景谷| 江门市| 莒南县| 邯郸县| 桦甸市| 专栏| 锦屏县| 高邮市| 绍兴市| 太原市| 天峻县| 枣阳市| 大城县| 嘉善县| 广丰县| 平度市| 阳曲县|