1038. Recover the Smallest Number (30)
来源:互联网 发布:手机淘宝网的评价管理 编辑:程序博客网 时间:2024/05/07 11:00
字符串采用排序的方式来决定哪个排在前面。比较大小的方式为:a+b<b+a。
代码参考别人。
#include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std; bool cmp(string a, string b) { return a+b < b+a; } int main() { int n; while(scanf("%d",&n)!=EOF) { std::vector<string> number(n); for(int i = 0; i < n; ++i) cin>>number[i]; //sort sort(number.begin(), number.end(), cmp); //get the first non-zero string ans; for(int i = 0; i < n; ++i) ans += number[i]; int non_zero = -1; for(int i = 0; i < ans.size(); ++i) if(ans[i] != '0') { non_zero = i; break; } if(non_zero == -1) printf("0\n"); else { ans = ans.substr(non_zero); cout<<ans<<endl; } } return 0; }
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)
- uva--10714+找规律
- PLSQL==>>游标
- 实习篇---第二天
- ognl.OgnlException: target is null for setProperty...
- Qt——续源文件打不开的问题
- 1038. Recover the Smallest Number (30)
- 缓冲区溢出攻击原理
- statusStrip的控件靠右停放——C#
- hdu1026---Ignatius and the Princess I
- Python的一点理解
- 软件工程第二次作业
- c:foreach p:datatable 嵌套刷新问题【备忘】
- .net如何将aspx生成html(cms静态页面原理)
- 启示录