Back to the Training Home
Back to the Training Home
Lesson: 40
Problem: 2857
Title: Digit Sorting
Difficulty Level: 1.5
Date: MAR 03, 2009
Site: http://acm.tju.edu.cn/toj/showp2857.html
Simple sorting problem.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int com(const void *a, const void *b) {
return *(char*)a - *(char*)b;
}
int getReverseNumber(int n) {
char num[100];
sprintf(num,"%d",n);
qsort(num,strlen(num),1,com);
return atoi(num);
}
void findResult(int n) {
int max = 0, m, rev;
for(int i = 0; i<n; i++) {
scanf("%d",&m);
rev = getReverseNumber(m);
if(rev > max) max = rev;
}
printf("%d\n",max);
}
int main() {
int n;
while(scanf("%d",&n) && n) {
findResult(n);
}
return 0;
}
|