Advertisement
MonsterScripter

CodinGame_2023_08_27__15_19_21__mountain.c

Aug 27th, 2023
1,331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. /**
  7.  * The while loop represents the game.
  8.  * Each iteration represents a turn of the game
  9.  * where you are given inputs (the heights of the mountains)
  10.  * and where you have to print an output (the index of the mountain to fire on)
  11.  * The inputs you are given are automatically updated according to your last actions.
  12.  **/
  13.  
  14. typedef struct pair {
  15.     int v1;
  16.     int v2;
  17. } pair;
  18.  
  19. int compare(const void* a, const void* b) {
  20.     const pair* p1 = (const pair*)a;
  21.     const pair* p2 = (const pair*)b;
  22.     return p1->v2 > p2->v2;
  23. }
  24.  
  25. int main() {
  26.     const int maxM = 8;
  27.     int index_highest_mountain = 0;
  28.     int max_highest_mounter = 0;
  29.     // game loop
  30.     while (1) {
  31.         for (int i = 0; i < maxM; i++) {
  32.             // represents the height of one mountain.
  33.             int mountain_h;
  34.             scanf("%d", &mountain_h);
  35.             if (max_highest_mounter < mountain_h) {
  36.                 max_highest_mounter = mountain_h;
  37.                 index_highest_mountain = i;
  38.             }
  39.         }
  40.         printf("%d\n", index_highest_mountain);
  41.         max_highest_mounter = 0;
  42.         index_highest_mountain = 0;
  43.     }
  44.     return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement