daily pastebin goal
91%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. enum { MAXN = 16384 };
  5.  
  6. struct St
  7. {
  8.     double x;
  9.     int ord;
  10.     int y;
  11. };
  12.  
  13. typedef struct St st;
  14.  
  15. int cmp(const void *a, const void *b) {
  16.     st f = *((st*)a);
  17.     st s = *((st*)b);
  18.     if (f.x != s.x) {
  19.         if (f.x < s.x) {
  20.             return -1;
  21.         } else if (f.x > s.x) {
  22.             return 1;
  23.         } else {
  24.             return 0;
  25.         }  
  26.     }
  27.     if (f.ord != s.ord) {
  28.         return f.ord - s.ord;
  29.     }
  30.     return f.y - s.y;
  31. }
  32.  
  33. int
  34. main(void) {
  35.     st data[MAXN];
  36.  
  37.     double x;
  38.     int y;
  39.     int ptr = 0;
  40.  
  41.     while (scanf("%lf %d", &x, &y) == 2) {
  42.         data[ptr].x = x;
  43.         data[ptr].ord = ptr;
  44.         data[ptr].y = y;
  45.         ptr++;
  46.     }
  47.  
  48.     qsort(data, ptr, sizeof(*data), cmp);
  49.  
  50.     for (int i = 0; i < ptr; i++) {
  51.         printf("%.10g %d\n", data[i].x, data[i].y);
  52.     }
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top