1038. Recover the Smallest Number
2015-10-28 15:11
429 查看
1038. Recover the Smallest Number (30)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders
of combinations of these segments, and the smallest number is 0229-321-3214-32-87.
Input Specification:
Each input file contains one test case. Each case gives a positive integer N (<=10000) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print the smallest number in one line. Do not output leading zeros.
Sample Input:
5 32 321 3214 0229 87
Sample Output:
22932132143287
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; vector<string> v; bool cmp(string A, string B) { if(A.size() > B.size()) { for(int i = 0; i < A.size(); i ++) { if(A[i] != B[i%B.size()]) return A[i] < B[i%B.size()]; } } else { for(int i = 0; i < B.size(); i ++) { if(A[i%A.size()] != B[i]) return A[i%A.size()] < B[i]; } } } int main() { int n; cin>>n; string s; for(int i = 0; i < n; i ++) { cin>>s; v.push_back(s); } sort(v.begin(), v.end(), cmp); string str; for(int i = 0; i < v.size(); i ++) str += v[i]; int index = 0; while(str[index] == '0') index ++; str.erase(0, index); if(str.size() == 0) cout<<"0"<<endl; else cout<<str<<endl; return 0; }
相关文章推荐
- Android简单逐帧动画Frame的实现(二)
- 将oracle从数据库32位平台迁移到64位置
- a+++++b的问题【转载】
- 安装了Ubuntu后Virtualbox的屏幕变小
- WinDBG加载符号表的一点心得体会
- 关于“Shader wants tangents, but the mesh doesn't have them”的解决
- CSS块级元素和行内元素
- 深度学习入门资料
- iphone上做webapp时总会识别一串数字为手机号码并变黑显示
- 不实现继承的抽象成员
- log4j.properties配置详解
- php如何获取文件的扩展名
- master数据库损坏的解决办法有哪些
- 关于iOS从iPod取出来的音乐MPMediaItemPropertyAssetURL属性为空问题
- Linux学习21_每天一个linux命令(30): chown命令
- Spring 的单个MongoTemplate配置中加入用户认证信息
- Activity 回调函数
- OC正则表达式的简单使用
- Eclipse和PyDev搭建完美Python开发环境(Windows篇)
- android的那几种动画