首页 > 其他 > 详细

1065. A+B and C (64bit) (20)

时间:2015-12-06 12:56:45      阅读:232      评论:0      收藏:0      [点我收藏+]

要输入字符串,longlongint不够

时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
HOU, Qiming

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
 


  1. #include <iostream>
  2. #include <math.h>
  3. #include <string>
  4. #define INF 10000000
  5. using namespace std;
  6. long long int ahigh=0, alow = 0, bhigh = 0, blow = 0, chigh = 0, clow = 0;
  7. bool Cmp(void) {
  8. if (ahigh + bhigh > chigh)
  9. return true;
  10. else if (ahigh + bhigh < chigh)
  11. return false;
  12. else {
  13. if (alow + blow > clow)
  14. return true;
  15. else
  16. return false;
  17. }
  18. }
  19. int main(void) {
  20. int n;
  21. cin >> n;
  22. for (int i = 0; i < n; i++) {
  23. string a, b, c;
  24. cin >> a >> b >> c;
  25. ahigh = 0;
  26. bhigh = 0;
  27. chigh = 0;
  28. alow = 0;
  29. blow = 0;
  30. clow = 0;
  31. if (a.length() > 9) {
  32. for (int j = 0; j < a.length() - 9; j++) {
  33. ahigh *= 10;
  34. ahigh = ahigh + a[j] - ‘0‘;
  35. }
  36. for (int j = a.length() - 9; j < a.length(); j++) {
  37. alow *= 10;
  38. alow = alow + a[j] - ‘0‘;
  39. }
  40. }
  41. else {
  42. ahigh = 0;
  43. for (int j = 0; j < a.length(); j++) {
  44. alow *= 10;
  45. alow = alow + a[j] - ‘0‘;
  46. }
  47. }
  48. if (b.length() > 9) {
  49. for (int j = 0; j < b.length() - 9; j++) {
  50. bhigh *= 10;
  51. bhigh = bhigh + b[j] - ‘0‘;
  52. }
  53. for (int j = b.length() - 9; j < b.length(); j++) {
  54. blow *= 10;
  55. blow = blow + b[j] - ‘0‘;
  56. }
  57. }
  58. else {
  59. bhigh = 0;
  60. for (int j = 0; j < b.length(); j++) {
  61. blow *= 10;
  62. blow = blow + b[j] - ‘0‘;
  63. }
  64. }
  65. if (c.length() > 9) {
  66. for (int j = 0; j < c.length() - 9; j++) {
  67. chigh *= 10;
  68. chigh = chigh + c[j] - ‘0‘;
  69. }
  70. for (int j = c.length() - 9; j < c.length(); j++) {
  71. clow *= 10;
  72. clow = clow + c[j] - ‘0‘;
  73. }
  74. }
  75. else {
  76. chigh = 0;
  77. for (int j = 0; j < c.length(); j++) {
  78. clow *= 10;
  79. clow = clow + c[j] - ‘0‘;
  80. }
  81. }
  82. if (Cmp())
  83. cout << "Case #" << i + 1 << ": true"<<endl;
  84. else
  85. cout << "Case #" << i + 1 << ": false"<<endl;
  86. }
  87. return 0;
  88. }





1065. A+B and C (64bit) (20)

原文:http://www.cnblogs.com/zzandliz/p/5023206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!