C++)
#include <iostream>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int a = n/5;
int b = -1;
int temp = 0;
while (a >= 0) {
temp = n - a * 5;
if ( temp % 3 == 0 ) {
b = temp / 3;
break;
}
else {
a--;
b = -1;
}
}
if (b == -1)
cout << -1;
else
cout << a + b;
return 0;
}
Python)
import sys
n = int(sys.stdin.readline().rstrip())
a = n//5
b = -1
temp = 0
while a >= 0:
temp = n - a * 5
if temp%3 == 0:
b = temp//3
break
else:
a -= 1
b = -1
print(-1 if b == -1 else a+b)'백준 1 > 구현' 카테고리의 다른 글
| [백준 13458] 시험감독 (C++/Python) (0) | 2020.12.06 |
|---|---|
| [백준 2960] 에라토스테네스의 체 (C++/Python) (0) | 2020.12.06 |
| [백준 1924] 2007년 (C++/Python) (0) | 2020.12.06 |