51 nod 1097 拼成最小的数 思路:字符串排序
来源:互联网 发布:阿里巴巴阿里云事业部 编辑:程序博客网 时间:2024/05/29 07:02
题目:
思路:1.以字符串输入这些整数。
2.对这些字符串排序,排序规则为尽量让能让结果变小的靠前。
代码中有注释,不懂的欢迎在博客中评论问我。
代码:
#include <bits\stdc++.h>using namespace std;string a[10001];//比较规则:尽量让结果字符串最小 bool cmp(string a,string b){ return a+b <= b+a; }int main(){ int n; cin >> n; for(int i = 0;i < n; i++){ cin >> a[i]; } sort(a,a + n,cmp); //排序 //因为要1000个字符空一行,所以先将结果存入到一个字符串 string s; for(int i = 0;i < n; i++){ s += a[i]; } for(int i = 0;s[i]; i++){ if(i%1000 == 0) cout << endl; //每1000个字符空一行,严格来说应该要排除i = 0 cout << s[i]; } return 0;} //writed by zhangjiuding
阅读全文
0 0
- 51 nod 1097 拼成最小的数 思路:字符串排序
- 51nod 1097 拼成最小的数 (排序)
- 51nod 1097 拼成最小的数 【简单排序】
- 51Nod 1097 拼成最小的数 排序
- 51NOD 1097 拼成最小的数
- 51nod 1097 拼成最小的数
- 51nod 1097 拼成最小的数
- 51Nod 1097 拼成最小的数
- 51nod 1097 拼成最小的数
- 51nod 1097 拼成最小的数
- 51nod 1097 拼成最小的数
- 51nod oj 1097 拼成最小的数 【贪心-结构体sort排序】
- 51Nod-1097-拼成最小的数
- 51nod 1097 拼成最小的数 思维
- 51nod 1097 拼成最小的数 思维题 t1+t2<t2+t1
- 1097 拼成最小的数
- 拼成最小的数
- 拼成最小的数
- Spring任务调度实战之Quartz Simple Trigger(转)
- 51nod 1393 0和1相等串 思路 : map存前缀和
- 51nod 1103 N的倍数 思路:抽屉原理+前缀和
- 分享一百多套开发视频教程的下载地址
- android开机自启动APP及使用adb命令测试
- 51 nod 1097 拼成最小的数 思路:字符串排序
- 生活随笔
- java实体转json忽略属性
- BeanUtils进行日期格式的拷贝转换
- 51 nod 1624 取余最长路 思路:前缀和 + STL(set)二分查找
- 写一个java死锁的demo
- 51 nod 1495 中国好区间 奇葩卡时间题 700ms 卡O(n*log(n)), 思路:O(n)尺取法
- Hybrid APP 混合开发模式的选择之路(六:JSBridge---Native代码与JS代码的通信桥梁)
- Flask框架+mySQL数据库:误删migrations文件夹后再次创建时遭遇错误(Can't locate revision identified by ‘xxx’)