1038. Recover the Smallest Number (30)
来源:互联网 发布:数据库第六版中文答案7 编辑:程序博客网 时间:2024/06/07 07:39
比较有趣的题,重点是写出(如果用<,9001,900110组合的9001900110明显比9001109001大)
bool compare(string a, string b){ return a + b < b + a;}
之后就string叠加,去掉开头的0,如果边空了输出0。
#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;bool compare(string a, string b){ return a + b < b + a;}int main(){ vector<string> st; int N; cin >> N; for (int t = 0;t < N;t++) { string temp; cin >> temp; st.push_back(temp); } sort(st.begin(), st.end(), compare); int i; string resault = ""; for (auto x : st) resault += x; auto it = find_if_not(resault.begin(), resault.end(), [](char a) {return a == '0';}); resault.assign(it, resault.end()); if (resault == "") cout << "0" << endl; else cout << resault << endl;}
0 0
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)-PAT
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- PAT 1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 【PAT】1038. Recover the Smallest Number (30)
- 1038. Recover the Smallest Number (30)
- 1112. Stucked Keyboard (20) -- 字符串处理,使用map
- 什么情况下用标准梯度下降法,什么情况下用随机梯度下降法
- 安装JDK,配置环境变量
- java代码规范
- UVA 147 Dollars (子集和问题 & DP)
- 1038. Recover the Smallest Number (30)
- 104. Maximum Depth of Binary Tree | 二叉树的深度
- Struts-setter、getter方法自动 ActionSupport类-属性驱动+模型驱动
- scala循环遍历
- Charles将指定的请求改为固定返回值
- pat a1002
- Fliptile [反转问题][dfs]
- 算法训练 6-1 递归求二项式系数值
- 初始结构体,计算量点距离