原题:

2857.   Digit Sorting


Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 3234   Accepted Runs: 1704


Several players play a game. Each player chooses a certain number, writes it down (in decimal notation, without leading zeroes) and sorts the digits of the notation in non-decreasing order, obtaining another number. The player who receives the largest number wins.

You are given the list of numbers initially chosen by the players. Output the winner's resulting number.

Input

The first line of each test case contains an integer N (1 ≤ N ≤ 50), indicating the number of the players. Then N integers followed in the second line. Each number will be between 0 and 100000, inclusive.

The input is terminated with N = 0.

Output

Output one line for each test case, indicating the winner's resulting number.

Sample Input

6
1 10 100 1000 10000 100000
3
9638 8210 331
0

Sample Output

1
3689

Source: TJU Team Selection Contest 2007 (1)

 

 

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <string.h>
 4 using namespace std;
 5
 6 int num[55];
 7 int b[55];
 8
 9 int main()    {
10     int N;
11     memset(b, 0, sizeof(b));
12     while (cin >> N && N != 0)    {
13         for (int k = 0; k < N; k++)    {
14             memset(num, 0, sizeof(num));
15             int n, count = 0; cin >> n;
16             for (int i = 0; i < 10; i++)        {
17                 num[i] = n % 10;
18                 n /= 10;    count++;
19                 if (n == 0)    break;
20             }
21             sort(num, num + count);
22             //9for (int i = 0; i < count; i++)    cout << "num["<<i<<"] "<<num[i]<<endl;
23             //memcpy(b, num, sizeof(b));
24             //cout << "b["<<k<<"] "<<b[k] << endl;
25             for (int i = 0; i < count; i++)    {
26                 if (num[i] != 0)    b[k] = b[k]*10 + num[i];
27             }
28             //cout << "b["<<k<<"] "<<b[k] << endl;
29         }
30         sort(b, b + N);
31         cout << b[N - 1] << endl;
32         memset(b, 0, sizeof(b));
33     }
34     return 0;
35 }

 

转载于:https://www.cnblogs.com/QingHuan/p/4263791.html

TJU Problem 2857 Digit Sorting相关推荐

  1. TJU Problem 1065 Factorial

    注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065.   Factorial Time Limit: 1.0 Seconds   Memory Limit ...

  2. TJU Problem 2520 Quicksum

    注意: for (int i = 1; i <= aaa.length(); i++) 其中是" i <= ",注意等号. 原题: 2520.   Quicksum T ...

  3. NCPC 2012 Problem B Bread Sorting

    题意是给一个数列,可以对三个数操作:把最后一个数放到第一个,前两个数后移一位.问最后能否到达相应的目标序列. 比如 1 2 3 会转换为3 1 2,多了两个逆序对. 给出两列数a和b,问a是否能变成b ...

  4. matlab 日期排序_在Matlab中对数据进行排序(Sorting Data in Matlab)

    在Matlab中对数据进行排序(Sorting Data in Matlab) 我试图在Matlab中对以下数据进行排序,但没有得到我需要的预期输出. 这是数据: '1B-3A-5A' '1A-3A- ...

  5. java python算法_用Python,Java和C ++示例解释的排序算法

    java python算法 什么是排序算法? (What is a Sorting Algorithm?) Sorting algorithms are a set of instructions t ...

  6. 合并排序算法排序过程_合并排序| 用于大型输入的最佳排序算法之一

    合并排序算法排序过程 What is sorting? 什么是分类? Sorting allows us to process our data in a more organized and eff ...

  7. 《算法导论》第二章 入门

    2.1 Insertion sort Pseudocode is used to specify a given algorithm in English. Issues of data abstra ...

  8. ICPC Central Russia Regional Contest (CRRC 19)

    ICPC Central Russia Regional Contest (CRRC 19) 文章目录 ICPC Central Russia Regional Contest (CRRC 19) A ...

  9. Codeforces Round #839 (Div. 3)题解

    A. A+B? 直接读入字符串然后把下标0和2的数字提取出来就行 // Problem: A. A+B? // Contest: Codeforces - Codeforces Round #839 ...

最新文章

  1. [转载]web集群时利用memcache来同步session
  2. php4种九九乘法表编程,PHP 99乘法表的几种实现代码
  3. Google怎么做(1.相关提示)
  4. 登陆界面(jsp)客户端验证
  5. linux无法将文件移入回收站,linux中使用rm命令将文件移到回收站的方法
  6. tcp报文格式_腾讯面试中的TCP/IP协议简述+经典面试题
  7. leetcode 题库894-- 所有可能的满二叉树
  8. Servlet3.0
  9. iOS :高德地图SDK配置教程(安装CocoaPods、生成Podfile文件、安装SDK、demo简单使用等)
  10. C++ TBB concurrent_unordered_map find() at() return static_cast<size_t>( t ) * internal::hash_multip
  11. APACHE 在windows下的配置
  12. EMUI10安装java_速升级!荣耀Play推EMUI 9.1正式版更新:方舟编译器和EROFS系统来了 - IT之家...
  13. 51单片机调整时钟Proteus仿真
  14. 2019高考(高中)数学必背重点公式大全
  15. JAVA走上证券行业
  16. 黑苹果gtx1050显卡驱动问题
  17. fmri|SPM contrast manager
  18. Web App与Native App
  19. 每晚定时重启IIS和数据库服务可节省服务器资源
  20. 1.人工智能早期知识表示方法

热门文章

  1. 如何将visual studio 2010编辑模式改为插入???
  2. Linux 修改yum 源
  3. python多线程下载文件
  4. 利用java反射调用类的的私有方法--转
  5. sqlite 修改表名,合并数据库(文件)
  6. ajax操作的链式写法
  7. php-数据分析 余弦相似度实现
  8. CImageList上的位图, CTabCtrl 还是用ICON好!
  9. 遇到了urlrewriter的:无法使用前导.. 在顶级目录上退出问题
  10. MONGODB 数据的存储顺序发现不是按_ID 的顺序存储的原因