toj 2857. Digit Sorting
来源:互联网 发布:茶叶网络推广 编辑:程序博客网 时间:2024/04/30 11:04
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. ThenN 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
61 10 100 1000 10000 10000039638 8210 3310
Sample Output
13689
#include<iostream>#include<string>#include<string.h>#include<algorithm>using namespace std;int f(char *s){int r=0,l;l=strlen(s);for(int i=0;i<l-1;i++){if(s[i]!='0'){r=r+s[i]-'0';r=r*10;}}r=r+s[l-1]-'0';return r;}int main(){char s1[100000];int l1,l2,n,sum=0,N;while(cin>>N&&N){sum=0;while(N--){cin>>s1;l1=strlen(s1);sort(s1,s1+l1);n=f(s1);//cout<<n<<endl;if(n>sum)sum=n;}cout<<sum<<endl;}return 0;}
0 0
- toj 2857. Digit Sorting
- TOJ 4483: Common Digit Pairs
- TOJ 10007 The last non-zero digit of n!
- [TOJ]1195. Sorting It All Out --拓扑排序
- Sorting
- Sorting:
- Sorting
- Sorting
- Sorting
- Sorting
- Sorting
- TOJ 2976
- toj 3140
- toj 1153
- TOJ 1772
- TOJ 3250
- TOJ 3051
- TOJ 4303
- 简单递归问题
- 【c++】计时函数
- 关于启动mysql服务1067错误
- 《编程珠玑(第2版)》笔记——将一个n元一维向量向左旋转i个位置(第2章)
- Android平台下驱动的开发及测试框架概述(二)
- toj 2857. Digit Sorting
- 基于SDL的SDL_mixer库的音乐播放器
- error: ‘for’ loop initial declarations are only allowed in
- hdu-1261
- JAVA编译过程
- 回复是对付对付对付多个发个
- POJ 3071 Football(简单 概率DP)
- c++11 Lambda函数与表示式
- spark 读取hadoop 格式的文件