본문 바로가기

분류 전체보기

(86)
백준 2420번 사파리월드 https://www.acmicpc.net/problem/2420 아이디어:절댓값을 활용할 수 있는지 묻는 문제1. 정수 범위가 넓어 long long 자료형 사용2. 정수 절댓값을 위해 cstdlib 라이브러리 > abs 함수 사용// 2420#include #include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n, m; cin >> n >> m; cout
백준 7287번 등록 https://www.acmicpc.net/problem/7287 아이디어:출력이 가능한지 묻는 문제내 프로필 > 맞았습니다를 출력해서 자꾸 틀렸는데 정답은 맞은 문제를 출력해야한다. // 7287#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout
백준 10699번 오늘 날짜 https://www.acmicpc.net/problem/10699 아이디어:1. 자기 언어에서 날짜를 출력할 수 있는지 묻는 문제ctime 라이브러리 include > time_t 구조체 > th 구조체와 localtime 함수로 시간 형식 // 10699#include #include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); time_t timer = time(NULL); struct tm* t = localtime(&timer); cout tm_year + 1900 tm_mon + 1 tm_mday; return 0;}
백준 1735번 분수 합 https://www.acmicpc.net/problem/1735 아이디어:1. 두 가지 방식: 최소 공배수를 구해서 먼저 분모를 만들고 계산할 지, 통분하고 합한 뒤에 기약분수로 변경할 지에서 후자 선택2. 우선 더하고3. 분자와 분모의 최대공약수를 따라 나눗셈4. 최대 공약수에는 유클리드 호제법 사용5. 유클리드 호제법을 위해 a > b 의 조건으로 수의 크기에 따라 정렬 // 1735#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); int a, b, c, d, e, f, r; cin >> a >> b; cin >> c >> d; e = (a * d) + (b * c); f = b * d; if ..
백준 13241번 최소공배수 https://www.acmicpc.net/problem/13241 아이디어:1. 1934번 최소공배수 문제 코드 재활용2. 큰 수의 배수 중에서 작은 수로 나누어 떨어지는 가장 작은 배수 출력 코드가 1934번과 완전 동일// 13241#include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long int a, b, m, result; cin >> a >> b; if (a > b) { for (int j = 1; (a * j)  모범답안: 1934번과 동일하게 유클리드 호제법으로 최대공약수를 구한 뒤a * b / 최대공약수 = 최소공배수 공식 이용