ASCII码排序

http://acm.hdu.edu.cn/showproblem.php?pid=2000

   1 /*written by czk*/
   2 #include <stdio.h>
   3 
   4 void swap(char *s, int i, int j) {
   5     char c = s[i];
   6     s[i] = s[j];
   7     s[j] = c;
   8 }
   9 
  10 int main() {
  11     char a[3];
  12     while(scanf("%1s%1s%1s", &a[0], &a[1], &a[2]) != EOF) {
  13         if(a[0] > a[1])
  14             swap(a, 0, 1);
  15         if(a[0] > a[2])
  16             swap(a, 0, 2);
  17         if(a[1] > a[2])
  18             swap(a, 1, 2);
  19         printf("%c %c %c\n", a[0], a[1], a[2]);
  20     }
  21 }

hdu2000 (2008-06-01 15:32:21由czk编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.