[algorithm] 백준 2490번 윷놀이

2025. 10. 18. 12:57·algorithm/기초 코드
반응형

 

윷을 던져 나온 정보가 0과 1로만 표시되기에

각 케이스마다 합을 구해서 판단하면 될 것이라 생각했다

 

#include <iostream>
#include <numeric>

using namespace std;

int main() {
    int arr[4] = {};
    
    for (int tmp = 0; tmp < 3; tmp++)
        {
            cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];
            int sum = accumulate(arr, arr+4, 0);
            
            if (sum == 1) cout << 'C'<< "\n";
            if (sum == 2) cout << 'B'<< "\n";
            if (sum == 3) cout << 'A'<< "\n";
            if (sum == 4) cout << 'E'<< "\n";
            if (sum == 0) cout << 'D'<< "\n";

            sum = 0;
            
        }
    return 0;
}

 

accumulate 함수를 사용했는데

첫번째 파라미터는 배열의 합을 구할 시작점

두번째는 배열의 합을 구할 끝 인덱스+1

세번째는 합의 초기값이다. 

 

accumulate 함수를 쓰기 위해서는

#include <numeric>을 선언해주어야 한다.

반응형

'algorithm > 기초 코드' 카테고리의 다른 글

[algorithm] 백준 2587번 대표값2  (0) 2025.10.18
[algorithm] 백준 2576번 홀수  (0) 2025.10.18
[algorithm] 백준 10093번 숫자  (0) 2025.10.12
[algorithm] 백준 2480번 주사위 세개  (0) 2025.10.12
[algorithm] 백준 2753번 윤년  (0) 2025.10.12
'algorithm/기초 코드' 카테고리의 다른 글
  • [algorithm] 백준 2587번 대표값2
  • [algorithm] 백준 2576번 홀수
  • [algorithm] 백준 10093번 숫자
  • [algorithm] 백준 2480번 주사위 세개
20puddle
20puddle
20puddle 님의 블로그 입니다.
  • 20puddle
    20puddle 님의 블로그
    20puddle
  • 전체
    오늘
    어제
    • 분류 전체보기 (100)
      • Spring boot (5)
      • git & github (5)
      • algorithm (47)
        • theory (3)
        • 배열 (7)
        • 연결 리스트 (3)
        • 스택 (5)
        • 큐 (3)
        • 덱 (2)
        • 기초 코드 (19)
        • BFS (5)
      • AI (43)
        • Machine Learning (35)
        • Deep Learning (8)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    알고리즘
    github
    그레디언트 클리핑
    인공지능
    Aimers
    딥러닝
    연결리스트
    주성분변환
    git
    홀드아웃 검증
    게시판
    오프라인 학습
    Java
    list
    ML
    DL
    Spring Boot
    머신러닝
    AI
    백준
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.3
20puddle
[algorithm] 백준 2490번 윷놀이
상단으로

티스토리툴바