문제 링크입니다: https://www.acmicpc.net/problem/1526
1526번: 가장 큰 금민수
첫째 줄에 N이 주어진다. N은 4보다 크거나 같고 1,000,000보다 작거나 같은 자연수이다.
www.acmicpc.net
모듈러 연산을 활용하는 간단한 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool isLikeable(int num) | |
{ | |
bool flag = true; | |
while (num) | |
{ | |
int checkNum = num % 10; | |
if (!(checkNum == 4 || checkNum == 7)) | |
{ | |
flag = false; | |
break; | |
} | |
num /= 10; | |
} | |
return flag; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
for (int i = N; i >= 1; i--) | |
{ | |
if (isLikeable(i)) | |
{ | |
cout << i << "\n"; | |
break; | |
} | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2615번 오목 (0) | 2020.02.03 |
---|---|
백준 17299번 오등큰수 (0) | 2020.01.31 |
백준 15596번 정수 N개의 합 (0) | 2020.01.30 |
백준 1816번 암호 키 (8) | 2019.11.25 |
백준 3671번 산업 스파이의 편지 (0) | 2019.11.24 |