본문 바로가기

분류 전체보기

(86)
백준 2920번 음계 https://www.acmicpc.net/problem/2920 아이디어:1. count 변수 > 인덱스 + 1 과 배열 값이 같으면 증가, 8 - 인덱스 와 배열 값이 같으면 감소2. count 변수가 8이면 ascending, -8이면 descending, default는 mixed 출력 // 2920#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); int note[8]; int count = 0; for (int i = 0; i > note[i]; } for (int i = 0; i
백준 2577번 숫자의 개수 https://www.acmicpc.net/problem/2577 아이디어:1. 문자열로 변환 후 각 문자에 접근해서 count 변수를 추가하고 출력2. switch case문 사용 // 2577#include #include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); int A, B, C, mul; string mul_result; int count_0 = 0, count_1 = 0, count_2 = 0, count_3 = 0, count_4 = 0; int count_5 = 0, count_6 = 0, count_7 = 0, count_8 = 0, count_9 = 0; cin >> A >> B >> C;..
백준 10250번 ACM 호텔 https://www.acmicpc.net/problem/10250 아이디어:1. H, W 준다고 2차원 배열 생각 X. W는 아예 쓰지도 않는 숫자2. 예제를 잘 보면 호수 앞자리는  N % H, 호수 뒷자리는 (N / H) + 13. 반례를 생각해보면 6 12 12가 주어졌을 때 003호가 아닌 602호가 배정되어야한다.4. N % H = 0 인 경우와 아닌 경우를 생각한다.5. 0인 경우 앞자리는 H, 뒷자리는 N / H6. 0이 아닌 경우 앞자리는 N % H, 뒷자리는 (N / H) + 17. string의 to_string()과 stoi()를 활용해서 int 와 string간의 형변환8. 뒷자리가 10을 넘지 않으면 중간에 0을 추가하고 10을 넘으면 그대로 출력 // 10250#include ..
백준 31403번 A+B-C https://www.acmicpc.net/problem/31403 아이디어:1. string 사용2. 숫자 (int) -> 문자열 (string): to_string(number)3. 문자열 (string) -> 숫자 (int): stoi(string)4. string에서 +는 붙이기 // 31403#include #include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); int a, b, c, result_1, result_2; string n, m; cin >> a; cin >> b; cin >> c; result_1 = a + b - c; n = to_string(a); m = to_string(b); ..
백준 2475번 검증수 https://www.acmicpc.net/problem/2475 아이디어:함수 작성 // 2475#include using namespace std;int calc(int a, int b, int c, int d, int e) { return ((a * a) + (b * b) + (c * c) + (d * d) + (e * e)) % 10;}int main() { ios::sync_with_stdio(false); cin.tie(NULL); int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e; f = calc(a, b, c, d, e); cout