선택은 나의 것

[SWEA] 8104 조 만들기 본문

☽ Algorithm/SWEA

[SWEA] 8104 조 만들기

Algoribi 2020. 5. 13. 17:22

문제

SWEA 8104 : 조 만들기

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

접근

1부터 n * k만큼 돌면서 조건에 맞게 등수를 더해주면 되는 문제이다. 

코드

// algorithm study
// SWEA_[D3]8104_조 만들기

#include <iostream>

using namespace std;

int main() {
    int test_case;
    cin >> test_case;
    for (int t = 0; t < test_case; t++) {
        int n, k, answer[21] = {0}, count = 1, chk = 0;
        cin >> n >> k;
        for (int i = 1; i <= n * k; i++) {
            answer[count] += i;
            if (chk == 0) {
                if (count == k)
                    chk = 1;
                else
                    count++;
            } else {
                if (count == 1)
                    chk = 0;
                else
                    count--;
            }
        }
        cout << "#" << t + 1 << " ";
        for (int i = 1; i <= k; i++) {
            cout << answer[i] << " ";
        }
        cout << "\n";
    }
    return 0;
}

 

깃 허브 주소 : https://github.com/algoribi/algorithm-study

'☽ Algorithm > SWEA' 카테고리의 다른 글

[SWEA] 1948 날짜 계산기  (0) 2020.05.14
[SWEA] 1946 간단한 압축 풀기  (0) 2020.05.14
[SWEA] 7853 오타  (0) 2020.05.13
[SWEA] 7732 시간 개념  (0) 2020.05.13
[SWEA] 7087 문제 제목 붙이기  (0) 2020.05.13
Comments