반응형
https://www.acmicpc.net/problem/9161
9161번: Sir Bedavere’s Bogus Division Solutions
The wise Sir Bedavere often uses non-standard logic, yet achieves positive results. Well, it seems he has been at it again, this time with division. He has determined that canceling the common digit of a numerator and denominator produces the correct answe
www.acmicpc.net
전수조사 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
사소한 경우(111의 배수)를 거르기 위해 trivialNum을 선언 후 111로 초기화해줍니다.
📔 풀이과정
분모와 분자의 세 자리들을 for loop를 수행하며 모두 탐색합니다.
두 가지의 경우에 해당하면 정답입니다.
1. 분자 / 분모 = 최 우측 자리 수 제거한 분자 / 최 좌측 자리 수 제거한 분모 이므로 분모 위치를 옮기면 다음과 같습니다.
분자 * 최 좌측 자리 수 제거한 분모 = 분모 * 최 우측 자리 수 제거한 분자
2. 제거한 자리들은 수가 같아야 합니다.
* 분모 분자가 모두 111의 배수라면 정답이 아니므로 continue해줍니다.
📔 정답출력
형식에 맞게 출력해줍니다.
📕 Code
'
#include <bits/stdc++.h>
using namespace std;
int trivialNum = 111;
int main(){
for(int top = 100; top <= 999; top++){
for(int bottom = 100; bottom <= 999; bottom++){
if(top % trivialNum == 0 && bottom % trivialNum == 0) continue;
if(bottom*(top / 10) == top*(bottom % 100) && (top % 10) == (bottom /100))
printf("%d / %d = %d / %d\n", top, bottom, top/10, bottom%100);
}
}
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Brute Force' 카테고리의 다른 글
(C++) - 백준(BOJ) 6987 : 월드컵 (0) | 2022.06.22 |
---|---|
(C++) - 백준(BOJ) 14625 : 냉동식품 (0) | 2022.06.20 |
(C++) - 백준(BOJ) 18409 : 母音を数える (Counting Vowels) (0) | 2022.06.15 |
(C++) - 백준(BOJ) 5046 : 전국 대학생 프로그래밍 대회 동아리 연합 (0) | 2022.05.31 |
(C++) - 백준(BOJ) 8295 : Rectangles (0) | 2022.05.30 |