CodingGame - The Descent

2020. 4. 27. 10:46알고리즘_생각하기/Coding Game

목표 : 우주선이 산에 충돌하지 않도록 가장 높은 산 부터 파괴하라

규칙 : 산의 갯수는 8개, 왼쪽 산부터 차례대로 높이를 알려줍니다.

텀 종료 시 가장 높은 산에 발포, 파괴해야 합니다.

우주선은 조금씩 하강합니다.

 

풀이

사용 언어 : C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * The while loop represents the game.
 * Each iteration represents a turn of the game
 * where you are given inputs (the heights of the mountains)
 * and where you have to print an output (the index of the mountain to fire on)
 * The inputs you are given are automatically updated according to your last actions.
 **/

int main()
{
    

    // game loop
    while (1) 
    {
        
        int  maxH = 0;
        int maxindex = 0;
    
        for (int i = 0; i < 8; i++)//산의 갯수는 8개
        { 
            
            int mountainH; // 산의 높이
              
            cin >> mountainH;//산의 높이를 입력받기
            cin. ignore();//실제로 입력하는 것이 아니라 시스템이 입력을 해 줌
            
            if( mountainH > maxH)//현재까지의 가장 높은 산보다 더 높으면 파괴할 목록에 넣기
            {
                maxH = mountainH;
                maxindex = i;
            }
            
          
            
            
        }
           
           cout << maxindex << endl; // The index of the mountain to fire on.

        // Write an action using cout. DON'T FORGET THE "<< endl"
        // To debug: cerr << "Debug messages..." << endl;

       
       
    }
}

 

'알고리즘_생각하기 > Coding Game' 카테고리의 다른 글

CodingGame - Temperatures  (0) 2020.04.27