1065. A+B and C (64bit) (20)
Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.
Input Specification:
The first line of the input gives the positive number of test cases, T (<=10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.
Output Specification:
For each test case, output in one line "Case #X: true" if A+B>C, or "Case #X: false" otherwise, where X is the case number (starting from 1).
Sample Input:
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
Sample Output:
Case #1: false
Case #2: true
Case #3: false
这一题的分不值高精度,但是题目的范围整数包括2^63啊,虽然测试数据没有;然后很奇怪的,第三个和第二个代码就是sum的区别,但是第三个代码就是过不了
评测结果
测试点
0 |
答案正确 |
1 |
308 |
12/12 |
1 |
答案正确 |
1 |
308 |
4/4 |
2 |
答案正确 |
1 |
436 |
4/4 |
#include <iostream>
#include<string>
using namespace std;
bool sighThesame(char yi, char er)
{
return (yi == '-'&&er == '-' || yi != '-'&&er != '-');
}
bool yiMax(string yi, string er)
{
if (sighThesame(yi[0], er[0]))
{
int cnt;
bool fs=false;
if (yi[0] == '-')
{
yi.erase(0, 1);
er.erase(0, 1);
fs = true;
}
cnt = yi.size() - er.size();
if (cnt > 0)er.insert(0, cnt, '0');
else yi.insert(0, -cnt, '0');
if (fs)return yi < er;
return yi > er;
}
return(yi[0] != '-');
}
void strdex(string*a, string*b,int end)
{
int c, at ;
at = (*a).size() - 1;
c = 0;
while (at > end)
{
c = (*a)[at] - (*b)[at] - c;
if (c >= 0)
{
(*a)[at] = c + '0';
c = 0;
}
else
{
(*a)[at] = c +10 + '0';
c = 1;
}
at--;
}
while (a->size() > 0 && (*a)[0] == '0')a->erase(0, 1);
}
void stradd(string*a, string*b, int end)
{
int c,at,bt;
at = (*a).size() - 1;
bt = (*b).size() - 1;
c = 0;
while (at > end || bt > end)
{
if (at > end&&bt > end)
{
c=(*a)[at] - '0' + (*b)[bt] - '0' + c;
(*a)[at] = c % 10 + '0';
c /= 10;
at--; bt--;
} else if (at > end)
{
c = (*a)[at] - '0' + c;
(*a)[at] = c % 10 + '0';
c /= 10;
at--;
}
else if (bt>end)
{
c = (*b)[bt] - '0' + c;
a->insert(at+1,1, c % 10 + '0');
c /= 10;
bt--;
}
}
if (c != 0)a->insert(at + 1, 1, c + '0');
}
void maxinterger(string*a, string*b,bool sighSame)
{ ;
if (sighSame)
{
if ((*a)[0] != '-') stradd(a, b, -1);
else stradd(a, b, 0);
}
else
{
bool fs=false;
int cnt;
if ((*a)[0] == '-')
{
fs = true;
a->erase(0, 1);
}
else b->erase(0, 1);
cnt = a->size() - b->size();
if (cnt>0)b->insert(0,cnt,'0');
else a->insert(0, -cnt, '0');
if ((*a) > (*b))
{
strdex(a, b, -1);
}
else if((*a)<(*b))
{
strdex(b, a, -1);
(*a)=(*b);
fs = !fs;
}
else
{
(*a) = "0";
fs = false;
}
if (a->size() > 0&&fs)
a->insert(0, 1,'-');
}
}
int main()
{
int T, index;
string a, b,c;
cin >> T;
for (index = 0; index < T;)
{
index++;
cin >> a >> b >>c;
maxinterger(&a, &b, sighThesame(a[0], b[0]));
cout << "Case #" << index << ": " <<
(yiMax(a, c) ? "true" : "false") << endl;
}
system("pause");
return 0;
}
评测结果
测试点
0 |
答案正确 |
1 |
308 |
12/12 |
1 |
答案正确 |
1 |
384 |
4/4 |
2 |
答案正确 |
1 |
308 |
4/4 |
#include <iostream>
using namespace std;
int main()
{
int T, index;
long long a, b, c,sum;
bool flag;
cin >> T;
for (index = 0; index < T;)
{
index++;
cin >> a >> b >> c;
sum = a + b;
if (a>0 && b > 0 && sum <= 0)flag = true;
else if(a < 0 && b < 0 && sum>= 0)flag = false;
else if (sum> c)flag = true;
else flag = false;
cout << "Case #" << index << ": " << (flag ? "true" : "false" )<< endl;
}
system("pause");
return 0;
}
评测结果
测试点
0 |
答案正确 |
1 |
436 |
12/12 |
1 |
答案错误 |
1 |
308 |
0/4 |
2 |
答案错误 |
1 |
436 |
0/4 |
#include <iostream>
using namespace std;
int main()
{
int T, index;
long long a, b, c;
bool flag;
cin >> T;
for (index = 0; index < T;)
{
index++;
cin >> a >> b >> c;
if (a>0 && b > 0 && (a + b) <= 0)flag = true;
else if(a < 0 && b < 0 && (a + b )>= 0)flag = false;
else if ((a + b )> c)flag = true;
else flag = false;
cout << "Case #" << index << ": " << (flag ? "true" : "false" )<< endl;
}
system("pause");
return 0;
}