📄 toj_2857.cpp
字号:
/*2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 369 Accepted Runs: 253Several 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.InputThe 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.OutputOutput one line for each test case, indicating the winner's resulting number.Sample Input61 10 100 1000 10000 10000039638 8210 3310Sample Output13689Source: TJU Team Selection Contest 1*/#include<cstdio>void scanfNum( int num[] , int const n ){ int i; for ( i = 0; i < n; i++ ) scanf( "%d" , &num[ i ] );}int sortNum( int numIn ){ char static digit[ 10 ]; int static i , j , len , multi10 , max , position , result ; for ( len = 0; numIn != 0; len++ ) { digit[ len ] = numIn % 10; numIn /= 10; } for ( i = 0; i < len - 1; i++ ) { max = digit[ i ]; position = i; for ( j = i + 1; j < len; j++ ) { if ( digit[ j ] > max ) { max = digit[ j ]; position = j; } } digit[ position ] = digit[ i ]; digit[ i ] = max; } for ( i = 0 , multi10 = 1 , result = 0 ; i < len; i++ , multi10 *= 10 ) { result += digit[ i ] * multi10; } return result;} void converse( int num[] , int const n ){ int i , j , k; for ( i = 0; i < n; i++ ) { num[ i ] = sortNum( num[ i ] ); }} int findMax ( int const num[] , int const n ){ int i , max; max = 0; for ( i = 0 ; i < n; i++ ) { if ( num[ i ] > max ) max = num[ i ]; } return max;} int main(){ int n , i , j , num[ 50 ] , max; while ( scanf( "%d" , &n ) && n != 0 ) { scanfNum( num , n ); converse( num , n ); max = findMax( num , n ); printf( "%d\n" , max ); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -