【STL】uva 10905 Children's Game
来源:互联网 发布:怎样去掉mac上win 编辑:程序博客网 时间:2024/06/06 09:50
题意:
给你n个数字,让你用这n个数组组成一个最大的数字并输出来。
思路:
给你n个数字,让你用这n个数组组成一个最大的数字并输出来。
思路:
这个题目看完第一反应就是直接按照字符串排序,然后轻轻松松写完,交上去直接wa了,为什么会wa呢?感觉也没啥特别的啊,但是看一组数据之后就明白了,9 90组合起来最大是990 而按照字符串排序的话是909因为90>9,所以直接按照字符串排序是错的,那么我们就回到问题的起点,想如果只有两个串a,b的时候我们怎么办,是不是如果a+b>b+a答案是ab否则答案是ba,所有串放在一起呢?也是这个道理,所以直接按照a+b>b+a排序,因为题目没有说每个数字是多少位的,同时string可以直接进项相加和比较,所以我们开string比较方便,但是如果要强行开char数组也行,直接模拟就行了。
///AC代码
#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;int cmp (string a, string b){ return a + b > b + a;}int main(){ string str[70]; int n; while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) { cin >> str[i]; } sort (str, str + n, cmp); for (int i = 0; i < n; i++) { cout << str[i]; } cout << endl; } return 0;}
阅读全文
0 0
- 【STL】uva 10905 Children's Game
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- uva 10905 - Children's Game
- UVA 10905 Children's Game
- UVa 10905 - Children's Game
- Uva-10905-Children’s Game
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905-Children’s Game
- UVa 10905: Children's Game
- UVA 10905 - Children's Game
- UVA 10905 Children's Game
- UVA 10905 - Children’s Game
- uva 10905 Children's Game
- CoolHash数据库引擎压测对比报告
- 南邮Inter多核实验二——Windows环境下多线程程序设计||
- bash基础特性之cut tr 详解与使用
- dpdk程序运行一段时间,收不到包,已解决
- VMware如何进入BIOS方法
- 【STL】uva 10905 Children's Game
- C++ 单例模式
- java实现哲学家进餐问题,及其死锁问题的解决
- Spark on YARN和MapReduce on YARN区别
- ubuntu-ssh no password
- 条件和分支语句
- excel使用技巧汇总
- 如何把一个数的位按四位进行相加
- 左值引用(&)以及右值引用(&&)(原创+转载)