Advertisement
MonsterScripter

CodinGame_2023_08_27__15_40_03__mountains.d

Aug 27th, 2023
2,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.94 KB | None | 0 0
  1. import std;
  2.  
  3. /**
  4.  * The while loop represents the game.
  5.  * Each iteration represents a turn of the game
  6.  * where you are given inputs (the heights of the mountains)
  7.  * and where you have to print an output (the index of the mountain to fire on)
  8.  * The inputs you are given are automatically updated according to your last actions.
  9.  **/
  10.  
  11. void main()
  12. {
  13.     const int maxM = 8;
  14.     int index_highest_mountain = 0;
  15.     int max_highest_mounter = 0;
  16.     // game loop
  17.     while (1) {
  18.         for (int i = 0; i < maxM; i++) {
  19.             int mountainH = readln.chomp.to!int; // represents the height of one mountain.
  20.             if (max_highest_mounter < mountainH) {
  21.                 max_highest_mounter = mountainH;
  22.                 index_highest_mountain = i;
  23.             }
  24.         }
  25.         writeln(index_highest_mountain); // The index of the mountain to fire on.
  26.         max_highest_mounter = 0;
  27.         index_highest_mountain = 0;
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement