【蠢问题】刚入门 想问为啥不能这么做
查看原帖
【蠢问题】刚入门 想问为啥不能这么做
418522
InfinityPeanut楼主2022/11/6 19:18
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	double a, b;
	double c, d;
	cin >> a >> b;
   if (a == 0) 
	{
		cout << 0 << endl;
	}
	c = pow(a, b);
	d = pow(10, 9);//不能超过
	if (c <= d) {
		cout << c;
	} else if ((c > d) || (-c <= d))//溢出都是那个值,直接判
		cout << "-1";

	return 0;
}

这样 60

dalao给的代码是

#include <iostream>
#include <cmath>
using namespace std;
unsigned long long a, b, c;

int main() {

	cin >> a >> b;
	if (a == 0) 
	{
		cout << 0 << endl;
		return 0;
	}
	c = pow(a, b);
	if ((c > long(1e9)) || c == 0 ) {
		cout << "-1";
		return 0;
	}
	cout << c << endl;
	return 0;
}

这个就AC了 为什么啊

2022/11/6 19:18
加载中...