[BaekJoon] 13752번 - 히스토그램 [Java][C++]
[BaekJoon] 13752번 - 히스토그램 [Java][C++]
1. 아이디어
반복문을 활용해서 각 테스트 케이스마다 k번 히스토그램을 출력하면 된다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
int k = Integer.parseInt(br.readLine());
sb.append("=".repeat(k)).append("\n");
}
System.out.println(sb);
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
while (n--) {
int k;
cin >> k;
cout << string(k, '=') << '\n';
}
}
3. 디버깅
없음.
4. 참고
없음.
This post is licensed under CC BY 4.0 by the author.