P1401 [入门赛 #18] 禁止在 int 乘 int 时不开 long long 题解
题目传送门
思路
这道题需要我们根据 int 类型的范围,所以需要开 long long 来存储并判断是否超过 int 类型的范围。
根据题意,我们直接将 int 最小值或 int 最大值就行了。
AC 记录
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long//全局long long
int x_1,x_2,y_1,y_2;
int N = INT_MAX-1;//int最大值
int M = 0-INT_MAX;//int最小值
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>x_1>>x_2;
cin>>y_1>>y_2;
if(x_1*y_1<M || x_1*y_1>N || x_1*y_2<M || x_1*y_2>N || x_2*y_1<M || x_2*y_1>N || x_2*y_2<M || x_2*y_2>N) cout<<"long long int";
else cout<<"int";
return 0;
}