标签:
原题:
You are given the list of numbers initially chosen by the players. Output the winner‘s resulting number.
The input is terminated with N = 0.
6 1 10 100 1000 10000 100000 3 9638 8210 331 0
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 }
TJU Problem 2857 Digit Sorting
标签:
原文地址:http://www.cnblogs.com/QingHuan/p/4263791.html