Advertisement
Andy_Lin

Zerojudge b604

Jul 26th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void pntbubbleSort(float array[][2], int size);
  5. void swap(float *a, float *b);
  6.  
  7. int main(void)
  8. {
  9.     int points;
  10.     scanf("%d", &points);
  11.     while (points != 0){
  12.         float pointArr[points][2];
  13.  
  14.         for (int i = 0; i < points; ++i){
  15.             float x, y;
  16.             scanf("%f %f", &x, &y);
  17.             pointArr[i][0] = x;
  18.             pointArr[i][1] = y;
  19.         }
  20.         pntbubbleSort(pointArr, points);
  21.  
  22.         /*
  23.         for (int i = 0; i < points; ++i){
  24.             printf("%f %f\n", pointArr[i][0], pointArr[i][1]);
  25.         }
  26.         */
  27.        
  28.         int check = 0;
  29.         int xcheck = pointArr[0][0] + pointArr[points - 1][0];
  30.         int ycheck = pointArr[0][1] + pointArr[points - 1][1];
  31.         for (int i = 0; i < points / 2; ++i){
  32.             if (pointArr[i][0] + pointArr[points - i - 1][0] == xcheck &&
  33.                 pointArr[i][1] + pointArr[points - i - 1][1] == ycheck){
  34.                 ++check;
  35.             }
  36.         }
  37.         if (check == points / 2){
  38.             printf("yes\n");
  39.         } else {printf("no\n");}
  40.  
  41.         scanf("%d", &points);
  42.     }
  43. }
  44.  
  45. void pntbubbleSort(float array[][2], int size)
  46. {
  47.     for (int pass = 1; pass < size; ++pass){
  48.         for (int count = 0; count < size - 1; ++count){
  49.             if (array[count][0] > array[count + 1][0]){
  50.                 swap(&array[count][0], &array[count + 1][0]);
  51.                 swap(&array[count][1], &array[count + 1][1]);
  52.             }
  53.             else if (array[count][0] == array[count + 1][0]){
  54.                 if (array[count][1] > array[count + 1][1]){
  55.                     swap(&array[count][0], &array[count + 1][0]);
  56.                     swap(&array[count][1], &array[count + 1][1]);
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
  62.  
  63. void swap(float *a, float *b)
  64. {
  65.     int hold = *a;
  66.     *a = *b;
  67.     *b = hold;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement