Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct event {
  4.     char person;
  5.     int a[2];
  6. } event;
  7.  
  8. int main(void) {
  9.     int x;
  10.     scanf("%i", &x);
  11.     for (int i = 0, y = x; i < y; i++) {
  12.         int rows;
  13.         scanf("%i", &rows);
  14.         int ptc;
  15.         event arr[rows];
  16.         for (int j = 0; j < rows; j++) {
  17.             int cfrequency = 0;
  18.             int cokfrequency = 0;
  19.             int jfrequency = 0;
  20.             int jokfrequency = 0;
  21.             scanf("%i %i", &arr[j].a[0], &arr[j].a[1]);
  22.             if (j == 0) {
  23.                 arr[0].person = 'C';
  24.             }
  25.             else if (j == 1) {
  26.                 arr[1].person = 'J';
  27.             }
  28.             else {
  29.                 ptc = j - 1;
  30.                 while (ptc >= 0) {
  31.                     if (arr[ptc].person == 'C') {
  32.                         cfrequency++;
  33.                         if (arr[j].a[0] >= arr[ptc].a[1] || arr[j].a[1] <= arr[ptc].a[0]) {
  34.                             cokfrequency++;
  35.                         }
  36.                     }
  37.                     else {
  38.                         jfrequency++;
  39.                         if (arr[j].a[0] >= arr[ptc].a[1] || arr[j].a[1] <= arr[ptc].a[0]) {
  40.                             jokfrequency++;
  41.                         }
  42.                     }
  43.                     ptc--;
  44.                 }
  45.                 if (cfrequency == cokfrequency) {
  46.                     arr[j].person = 'C';
  47.                 }
  48.                 else if (jfrequency == jokfrequency) {
  49.                     arr[j].person = 'J';
  50.                 }
  51.                 else {
  52.                     arr[0].person = 'A';
  53.                     ptc = 0;
  54.                 }
  55.             }
  56.         }
  57.         if (arr[0].person == 'A')
  58.         {
  59.             printf("Case #%i: IMPOSSIBLE", i + 1);
  60.         }
  61.         else
  62.         {
  63.             printf("Case #%i: ", i + 1);
  64.             for (int b = 0; b < rows; b++)
  65.             {
  66.                 printf("%c", arr[b].person);
  67.             }
  68.         }
  69.     printf("\n");
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement