{"id":1458,"date":"2015-02-22T20:55:28","date_gmt":"2015-02-22T12:55:28","guid":{"rendered":"http:\/\/boweihe.me\/?p=1458"},"modified":"2015-02-22T20:55:28","modified_gmt":"2015-02-22T12:55:28","slug":"1065-ab-and-c-64bit-20","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=1458","title":{"rendered":"1065. A+B and C (64bit) (20)"},"content":{"rendered":"<p><a href=\"http:\/\/www.patest.cn\/contests\/pat-a-practise\/1065\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.patest.cn\/contests\/pat-a-practise\/1065<\/a><\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><strong>\u539f\u9898\u5982\u4e0b<\/strong><\/p>\n<p>Given three integers A, B and C in [-2<sup>63<\/sup>, 2<sup>63<\/sup>], you are supposed to tell whether A+B &gt; C.<br \/>\n<b>Input Specification:<\/b><br \/>\nThe first line of the input gives the positive number of test cases, T (&lt;=10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.<br \/>\n<b>Output Specification:<\/b><br \/>\nFor each test case, output in one line &#8220;Case #X: true&#8221; if A+B&gt;C, or &#8220;Case #X: false&#8221; otherwise, where X is the case number (starting from 1).<br \/>\n<b>Sample Input:<\/b><\/p>\n<pre>3\n1 2 3\n2 3 4\n9223372036854775807 -9223372036854775808 0\n<\/pre>\n<p><b>Sample Output:<\/b><\/p>\n<pre class=\"\">Case #1: false\nCase #2: true\nCase #3: false<\/pre>\n<hr \/>\n<p>&nbsp;<br \/>\n\u5206\u6790\uff0c\u5176\u5b9e\u5c31\u662f\u81ea\u5df1\u505a\u52a0\u51cf\u6cd5\u8fdb\u4f4d\u7684\u95ee\u9898\uff0c\u9700\u8981\u8003\u8651\u6b63\u8d1f\u53f7\u7684\u7ec6\u8282\u3002<br \/>\n\u6b63\u8d1f\u6570\u52a0\u51cf\u6cd5\u7684\u89c4\u5219\u53ef\u4ee5\u53c2\u8003\u767e\u5ea6\u6587\u5e93\uff0c\u4e00\u5927\u5806\u5c0f\u5b66\u751f\u6559\u6750\uff0c\u54c8\u54c8~<br \/>\n\u5927\u6982\u662f\u8fd9\u6837\uff0c\u6bd4\u8f83\u4e24\u4e2a\u6570a\u548cb\uff1a<\/p>\n<ul>\n<li>\u6700\u7ec8\u7ed3\u679c\u7b26\u53f7\u7684\u5224\u5b9a\uff1a\u5982\u679c|a|&gt;=|b|\u90a3\u4e48\u7ed3\u679c\u7684\u7b26\u53f7\u4e0ea\u76f8\u540c\uff0c\u53cd\u4e4b\u7b26\u53f7\u4e0eb\u76f8\u540c\uff1b<\/li>\n<li>\u6570\u503c\u8ba1\u7b97\uff0c\u4e0d\u7ba1\u6b63\u8d1f\u53f7\uff0c\u7528\u7edd\u5bf9\u503c\u5927\u7684\u90a3\u4e2a\u505a<em>\u64cd\u4f5c\u65701<\/em>\uff0c\u7edd\u5bf9\u503c\u5c0f\u7684\u505a<em>\u64cd\u4f5c\u65702<\/em>\uff0c\u5982\u679ca\uff0cb\u540c\u53f7\u505a<em>\u64cd\u4f5c\u65701<\/em>+<em>\u64cd\u4f5c\u65702<\/em>\uff0c\u5f02\u53f7\u505a<em>\u64cd\u4f5c\u65701<\/em>&#8211;<em>\u64cd\u4f5c\u65702<\/em>\uff1b<\/li>\n<\/ul>\n<hr \/>\n<p>&nbsp;<br \/>\n<strong>\u6211\u7684\u4ee3\u7801<\/strong>\uff08\u597d\u4e45\u6ca1\u5199c++\uff0c\u5404\u79cd\u590d\u6742\uff0c\u89c1\u8c05\uff09<br \/>\n\u5176\u4e2disBiggerAbs\u662f\u5224\u65ada\u4e0eb\u7684\u7edd\u5bf9\u503c\u5927\u5c0f\u7684\uff0cisBigger\u662f\u5224\u65ad\u5b9e\u9645\u503c\u5927\u5c0f\u7684\uff0cswapss\u662f\u4ea4\u6362\u5143\u7d20\u3002<br \/>\n\u53e6\u59160x30\u662f\u5b57\u7b26&#8217;0&#8217;\u7684ASCII\u7801\u6765\u7740~\u8f93\u5165\u7684\u65f6\u5019\u662f\u6309\u7167\u5b57\u7b26\u6d41\u770b\u5f85\u7684\uff0c\u8ba1\u7b97\u7684\u65f6\u5019\u8f6c\u6362\u6210\u4e86\u6570\u5b57\uff0c\u7136\u540e\u6bd4\u8f83\u7684\u65f6\u5019\u4e3a\u4e86\u548cc\u6bd4\u65b9\u4fbf\u53c8\u8f6c\u6362\u56de\u53bb\u4e86\u3002<br \/>\n\u53e6\u5916\u7ed9\u7684Sample Input\u91cc\u9762\u90a3\u4e2a\u4e00\u957f\u4e32\u7684\u5c31\u662f\u4e0a\u9650\u548c\u4e0b\u9650\u4e86\uff0c\u52a0\u4e0a\u7b26\u53f720\u4f4d\u8db3\u591f\u653e\u3002<\/p>\n<pre class=\"lang:c++ decode:true\">#include &lt;iostream&gt;\n#include &lt;string.h&gt;\nusing namespace std;\nvoid swapss(char*a, char* b)\n{\n\tchar t[20];\n\tstrcpy(t, a);\n\tstrcpy(a, b);\n\tstrcpy(b, t);\n}\nbool isBiggerAbs(char* a, char* b)\n{\n\tint len_a, len_b;\n\tlen_a = strlen(a);\n\tlen_b = strlen(b);\n\tif (len_a &gt; len_b)\n\t\treturn true;\n\telse if (len_a &lt; len_b)\n\t\treturn false;\n\t\/\/\u53ea\u9700\u6bd4\u8f83\u4f4d\u6570\u4e00\u6837\u7684\n\tfor (int i = 0; i &lt; len_a; i++)\n\t{\n\t\tif (a[i] &gt; b[i])\n\t\t\treturn true;\n\t\telse if (a[i] &lt; b[i])\n\t\t\treturn false;\n\t}\n\t\/\/\u5b8c\u5168\u76f8\u7b49\n\treturn false;\n}\nbool isBigger(char* a, char* b)\n{\n\t\/\/Judge if a &gt; b\n\tbool neg_a = (a[0] == '-');\n\tbool neg_b = (b[0] == '-');\n\tif (neg_a &amp;&amp; !neg_b)\n\t\treturn false;\n\telse if (!neg_a &amp;&amp; neg_b)\n\t\treturn true;\n\tif (!neg_a)\n\t\treturn isBiggerAbs(a, b);\n\telse\n\t{\n\t\ta = strtok(a, \"-\");\n\t\tb = strtok(b, \"-\");\n\t\treturn !isBiggerAbs(a, b);\n\t}\n}\nvoid bigPlus(char* a, char* b, char* r)\n{\n\t\/\/ c = a + b\n\tint len_a, len_b;\n\tbool isNeg_a = false;\n\tbool isNeg_b = false;\n\tbool isNeg_r = false;\n\tif (a[0] == '-')\n\t{\n\t\tchar* pch = strtok(a, \"-\");\n\t\ta = pch;\n\t\tisNeg_a = true;\n\t}\n\tif (b[0] == '-')\n\t{\n\t\tchar* pch = strtok(b, \"-\");\n\t\tb = pch;\n\t\tisNeg_b = true;\n\t}\n\tif (!isBiggerAbs(a, b))\n\t{\n\t\t\/\/Swap a and b\n\t\tswapss(a, b);\n\t\tisNeg_r = isNeg_b;\n\t}\n\telse\n\t\tisNeg_r = isNeg_a;\n\tif (isNeg_a)\n\t{\n\t\tbool t = isNeg_a;\n\t\tisNeg_a = isNeg_b;\n\t\tisNeg_b = t;\n\t}\n\tlen_a = strlen(a);\n\tlen_b = strlen(b);\n\tint index_a = len_a - 1;\n\tint index_b = len_b - 1;\n\tint remainder = 0;\n\tint count = 0;\n\twhile (index_a &gt;= 0 || index_b &gt;= 0)\n\t{\n\t\tint op0 = 0;\n\t\tif (index_a &gt;=0 )\n\t\t\top0 = (int)a[index_a] - 0x30;\n\t\tif (isNeg_a)\n\t\t\top0 = -op0;\n\t\tint op1 = 0;\n\t\tif (index_b &gt;= 0)\n\t\t\top1 = (int)b[index_b] - 0x30;\n\t\tif (isNeg_b)\n\t\t\top1 = -op1;\n\t\tint result = op0 + op1 + remainder;\n\t\tif (result &lt; 0)\n\t\t{\n\t\t\tremainder = -1; \/\/negative raminder (&lt;'0')\n\t\t\tresult += 10;\n\t\t}\n\t\telse if (result &gt; 9)\n\t\t{\n\t\t\tremainder = 1; \/\/positive remainder (&gt;'9')\n\t\t\tresult -= 10;\n\t\t}\n\t\telse\n\t\t\tremainder = 0;\n\t\tr[count++] = (char)(result + 0x30);\n\t\tindex_a--;\n\t\tindex_b--;\n\t}\n\t\/\/Deal with the last remainder\n\tif (remainder &gt; 0)\n\t{\n\t\tr[count++] = (char)(remainder+0x30);\n\t}\n\telse if (remainder &lt; 0)\n\t{\n\t\tr[count++] = (char)(remainder + 0x30);\n\t}\n\tif (isNeg_r)\n\t\tr[count++] = '-';\n\tchar temp[21];\n\tint t = 0;\n\twhile ((--count) &gt;= 0)\n\t{\n\t\ttemp[t++] = r[count];\n\t}\n\ttemp[t] = '\\0';\n\tstrcpy(r, temp);\n}\nint main()\n{\n\t\/\/Read huge integer as charset\n\tint T; \/\/Nubmer of test cases\n\tcin &gt;&gt; T;\n\tchar a[20];\n\tchar b[20];\n\tchar c[20];\n\tchar result[21];\n\tfor (int i = 0; i &lt; T; i++)\n\t{\n\t\t\/\/Deal with test cases\n\t\tcin &gt;&gt; a &gt;&gt; b &gt;&gt; c;\n\t\tbigPlus(a, b, result);\n\t\tbool is_bigger = isBigger(result, c);\n\t\tcout &lt;&lt; \"Case #\" &lt;&lt; i + 1 &lt;&lt; \": \";\n\t\tif (is_bigger)\n\t\t\tcout &lt;&lt; \"true\";\n\t\telse\n\t\t\tcout &lt;&lt; \"false\";\n\t\tif (i &lt; T - 1)\n\t\t\tcout &lt;&lt; endl;\n\t}\n\treturn 0;\n}<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>\u7ed3\u679c<\/p>\n<h2>\u8bc4\u6d4b\u7ed3\u679c<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u65f6\u95f4<\/th>\n<th>\u7ed3\u679c<\/th>\n<th>\u5f97\u5206<\/th>\n<th>\u9898\u76ee<\/th>\n<th>\u8bed\u8a00<\/th>\n<th>\u7528\u65f6(ms)<\/th>\n<th>\u5185\u5b58(kB)<\/th>\n<th>\u7528\u6237<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><span title=\"2015\u5e742\u670822\u65e5 20:46\">2\u670822\u65e5 20:46<\/span><\/td>\n<td><span class=\"submitRes-3\">\u7b54\u6848\u6b63\u786e<\/span><\/td>\n<td><a href=\"http:\/\/www.patest.cn\/submissions\/1086404\">20<\/a><\/td>\n<td><a href=\"http:\/\/www.patest.cn\/contests\/pat-a-practise\/1065\">1065<\/a><\/td>\n<td><a href=\"http:\/\/www.patest.cn\/submissions\/1086404\/source\">C++ (g++ 4.7.2)<\/a><\/td>\n<td>1<\/td>\n<td>360<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u6d4b\u8bd5\u70b9<\/h2>\n<table id=\"case_result_list\">\n<thead>\n<tr>\n<th class=\"header\">\u6d4b\u8bd5\u70b9<\/th>\n<th class=\"header\">\u7ed3\u679c<\/th>\n<th class=\"header\">\u7528\u65f6(ms)<\/th>\n<th class=\"header\">\u5185\u5b58(kB)<\/th>\n<th class=\"header\">\u5f97\u5206\/\u6ee1\u5206<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0<\/td>\n<td><span class=\"caseRes-3\">\u7b54\u6848\u6b63\u786e<\/span><\/td>\n<td>1<\/td>\n<td>360<\/td>\n<td>12\/12<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td><span class=\"caseRes-3\">\u7b54\u6848\u6b63\u786e<\/span><\/td>\n<td>1<\/td>\n<td>360<\/td>\n<td>4\/4<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><span class=\"caseRes-3\">\u7b54\u6848\u6b63\u786e<\/span><\/td>\n<td>1<\/td>\n<td>360<\/td>\n<td>4\/4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.patest.cn\/contests\/pat-a-practise\/1065 &nbsp; \u539f\u9898\u5982\u4e0b Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B &gt; C. Input Specification: The first line of the input gives the positive number of test cases, T (&lt;=10). Then T test cases follow, each consists of a single line containing three integers A, B [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[28,84,186],"class_list":["post-1458","post","type-post","status-publish","format-standard","hentry","category-study","category-technical","tag-c","tag-pat","tag-186"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1458"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1458\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}