Uva10905
来源:互联网 发布:php代码质量分析 编辑:程序博客网 时间:2024/06/10 23:49
Childrens Game
There are lots of number games for children. These games are pretty easy to play but not so easy to make. We will discuss about an interesting game here. Each player will be givenN positive integer. (S)He can make a big integer by appending those integers after one another. Such as if there are 4 integers as 123, 124, 56, 90 then the following integers can be made 1231245690, 1241235690, 5612312490, 9012312456, 9056124123 etc. In fact 24 such integers can be made. But one thing is sure that 9056124123 is the largest possible integer which can be made.
You may think that its very easy to find out the answer but will it be easy for a child who has just got the idea of number?
Input
Each input starts with a positive integer N (≤ 50). In next lines there areN positive integers. Input is terminated by N = 0, which should not be processed.
Output
For each input set, you have to print the largest possible integer which can be made by appending all theN integers.
Sample Input4
123 124 56 90
5
123 124 56 90 9
5
9 9 9 9 9
0
Output for Sample Input
9056124123
99056124123
99999
解题思路:
题意就是先给一个n,然后输入n个数,问这n个数按怎样顺序排列可以得到的最大数,输出排列得到的最大数。
总结起来就是string用处大,开一个string数组s,然后n个输入都变成string类型,因为string类型有+、- 等运算符
的重载,所以可以直接进行把两个串加上的操作,依次比较相邻两个数,看哪个在前得到的串比较大。sort后得到的串
就是n个数能组成的最大值,输出即可。新技能get√
AC代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <cassert>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>#define REP0(i, n) for (int i=0;i<int(n);++i)#define REP1(i, n) for (int i=1;i<=int(n);++i)#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)using namespace std;#define REP(i, n) for (int i=0;i<int(n);++i)#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)#define REP_1(i, n) for (int i=1;i<=int(n);++i)#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)#define REP_N(i, n) for (i=0;i<int(n);++i)#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)#define REP_1_N(i, n) for (i=1;i<=int(n);++i)#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)#define REP_C_N(i, n) for (n____=int(n),i=0;i<n____;++i)#define FOR_C_N(i, a, b) for (b____=int(b),i=a;i<b____;++i)#define DWN_C_N(i, b, a) for (a____=int(a),i=b-1;i>=a____;--i)#define REP_1_C_N(i, n) for (n____=int(n),i=1;i<=n____;++i)#define FOR_1_C_N(i, a, b) for (b____=int(b),i=a;i<=b____;++i)#define DWN_1_C_N(i, b, a) for (a____=int(a),i=b;i>=a____;--i)#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)#define REP_S(it, str) for (char*it=str;*it;++it) // 用于字符串的 .. .#define REP_G(it, u) for (int it=hd[u];it;it=suc[it]) // 用于图论的 .. .#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )#define REP_2(i, j, n, m) REP(i, n) REP(j, m)#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)#define PB push_back#define MP(A, B) make_pair(A, B)#define PTT pair<T, T>#define fi first#define se second#define Display(A, n, m) { \ REP(i, n){ \ REP(j, m) cout << A[i][j] << " "; \ cout << endl; \ } \}#define Display_1(A, n, m) { \ REP_1(i, n){ \ REP_1(j, m) cout << A[i][j] << " "; \ cout << endl; \ } \}typedef long long LL;typedef double DB;typedef unsigned UINT;typedef unsigned long long ULL;const int dx[] = {-1, 0, 1, 0};const int dy[] = {0, 1, 0, -1};const int MOD = 1000000007;const int INF = 0x3f3f3f3f;const LL INFF = 1LL << 60;const DB EPS = 1e-9;const DB OO = 1e15;const DB PI = acos(-1.0); //M_PI;#define N 100010string s[N];bool cmp(string a , string b){ string x = a + b; string y = b + a; return x > y;}int main(){ #ifdef ZH freopen("in.txt","r",stdin); #endif int n; while(~scanf("%d",&n)) { if(n == 0) break; REP(i , n) cin >> s[i]; sort(s , s + n , cmp); REP(i , n) cout << s[i] ; cout <<endl; }}
- uva10905
- UVA10905
- uva10905
- uva10905
- Uva10905
- UVA10905
- uva10905
- uva10905
- uva10905
- uva10905
- uva10905
- UVa10905
- uva10905 - Children's Game
- Uva10905 Children's Game
- uva10905-Children's Game
- UVA10905- Children's Game
- UVA10905 - Children's Game
- UVA10905孩子们的游戏
- 黑马程序员_线程并发库
- hdu 4858 项目管理(vector模拟)
- 链条式编程
- 将博客搬至CSDN
- hdu1161 Eddy's mistakes
- Uva10905
- PHP开发调试插件xdebug安装与配置
- hadoop format之后datanode起不了解决方法
- Mybatis源码学习
- SIFT matlab代码中的若干疑惑和解释
- 也谈一下TCP segment of a reassembled PDU
- nike sale ypwn
- fifa coins online iqkm
- fifa 14 coins bybk