문제링크 : https://www.acmicpc.net/problem/32278
# 자료형 범위 설정
SHORT_MIN = -32768
SHORT_MAX = 32767
INT_MIN = -2147483648
INT_MAX = 2147483647
LONGLONG_MIN = -9223372036854775808
LONGLONG_MAX = 9223372036854775807
number = int(input())
if SHORT_MIN <= number <= SHORT_MAX:
print("short")
elif INT_MIN <= number <= INT_MAX:
print("int")
elif LONGLONG_MIN <= number <= LONGLONG_MAX:
print("long long")
#include <iostream>
#include <limits>
using namespace std;
int main() {
long long number;
cin >> number;
if (number >= numeric_limits<short>::min() && number <= numeric_limits<short>::max()) {
cout << "short\n";
}
else if (number >= numeric_limits<int>::min() && number <= numeric_limits<int>::max()) {
cout << "int\n";
}
else if (number >= numeric_limits<long long>::min() && number <= numeric_limits<long long>::max()) {
cout << "long long\n";
}
return 0;
}
c++처럼 아예 값이 존재하는 경우 직접 사용하고, 없는 경우 직접 할당하여 사용합니다
반응형
'2.알고리즘 > 백준' 카테고리의 다른 글
백준 32314 Christmas Tree Adapter python / c++ (0) | 2024.09.27 |
---|---|
백준 31822 재수강 python / c++ (0) | 2024.05.17 |
백준 31821 학식 사주기 python / c++ (0) | 2024.05.14 |
백준 31775 글로벌 포닉스 python / c++ (0) | 2024.04.30 |