코딩테스트/코드업
[코드업] 나도 IQ 150 (C++)
Deff_a
2024. 4. 10. 15:41
나도 IQ 150
첫 줄에 이 삼각격자의 세로 길이 N이 입력된다.(2 <= N <= 20) 둘째 줄부터 N+1째 줄까지 (k, 1)의 격자판의 정보가 입력된다. ( 1 <= k <= N)
codeup.kr
문제
이 문제는 각 x열의 y 값이 x의 값 만큼 증가할 때, (x - 1, y) 좌표의 값을 빼서 (x, y + 1) 값을 구하는 문제이다.
n과 (0 ~ n, 0)의 숫자가 입력될 경우, n 크기의 삼각 격자판을 출력한다.

6 - 4 = 2
9 - 6 = 3
3 - 2 = 1 ...
풀이
#include <iostream>
// https://codeup.kr/problem.php?id=1508
using namespace std;
int map[20][20] = { 0, };
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> map[i][0]; // 입력
for (int j = 0; j < i; j++) { // 계산
map[i][j + 1] = map[i][j] - map[i - 1][j] ;
}
}
for (int i = 0; i < n; i++) { // 출력
for (int j = 0; j <= i; j++) {
cout << map[i][j] << " ";
}
cout << endl;
}
return 0;
}
CodingTestPractice/CodeUp/2차원 배열/나도 IQ 150.cpp at main · seungdo1234/CodingTestPractice
코딩 테스트 연습. Contribute to seungdo1234/CodingTestPractice development by creating an account on GitHub.
github.com