{"id":1310,"date":"2014-10-02T12:50:49","date_gmt":"2014-10-02T04:50:49","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=1310"},"modified":"2014-10-02T12:50:49","modified_gmt":"2014-10-02T04:50:49","slug":"pat-1012-the-best-rank-25","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=1310","title":{"rendered":"PAT 1012. The Best Rank (25)"},"content":{"rendered":"<blockquote><p>To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C &#8211; C Programming Language, M &#8211; Mathematics (Calculus or Linear Algebra), and E &#8211; English. At the mean time, we encourage students by emphasizing on their best ranks &#8212; that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.<br \/>\nFor example, The grades of C, M, E and A &#8211; Average of 4 students are given as the following:<\/p>\n<pre>StudentID  C  M  E  A\n310101     98 85 88 90\n310102     70 95 88 84\n310103     82 87 94 88\n310104     91 91 91 91\n<\/pre>\n<p>Then the best ranks for all the students are <i>No.1<\/i> since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.<br \/>\n<b>Input<\/b><br \/>\nEach input file contains one test case. Each case starts with a line containing 2 numbers N and M (&lt;=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.<br \/>\n<b>Output<\/b><br \/>\nFor each of the M students, print in one line the best rank for him\/her, and the symbol of the corresponding rank, separated by a space.<br \/>\nThe priorities of the ranking methods are ordered as A &gt; C &gt; M &gt; E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.<br \/>\nIf a student is not on the grading list, simply output &#8220;N\/A&#8221;.<br \/>\n<b>Sample Input<\/b><\/p>\n<pre>5 6\n310101 98 85 88\n310102 70 95 88\n310103 82 87 94\n310104 91 91 91\n310105 85 90 90\n310101\n310102\n310103\n310104\n310105\n999999\n<\/pre>\n<p><b>Sample Output<\/b><\/p>\n<pre class=\"\">1 C\n1 M\n1 E\n1 A\n3 A\nN\/A<\/pre>\n<p>===============================================<\/p><\/blockquote>\n<hr \/>\n<p>\u53c8\u56de\u6765\u505aPAT\u9898\u76ee\u4e86\uff0cC++\u90fd\u5fd8\u5f97\u5dee\u4e0d\u591a\u5e72\u51c0\u4e86\u6709\u6ca1\u6709\uff01\u4e0b\u6b21\u5c1d\u8bd5\u4e0b\u63d0\u4ea4Python\u7684\u7b54\u6848\u5427~\u8bf6\u563f\u563f<br \/>\n\u8fd9\u9053\u9898\u6ca1\u4ec0\u4e48\u96be\u7684\uff0c\u56e0\u4e3a\u5b83\u65f6\u95f4\u8981\u6c42\u4e0d\u9ad8\u3002<br \/>\n\u6211\u505a\u4e86\u4e2a\u94fe\u8868\u628a\u5b66\u751f\u6210\u7ee9\u7684\u8282\u70b9\u8fde\u8d77\u6765\uff0c\u8fd9\u6837\u662f\u56e0\u4e3a\u5b66\u53f7\u67096\u4f4d\u6570\uff08\u5176\u5b9e\u8981\u662f\u5f04\u4e2a1000000\u884c\u7684\u77e9\u9635\u4e5f\u6ca1\u4ec0\u4e48\u4e86\u4e0d\u8d77\u7684\u561b\u54fc\uff01\uff09\uff0c\u53cd\u6b63\u4e4b\u540e\u5c31\u662f\u94fe\u8868\u67e5\u627e\u7684\u95ee\u9898\u4e86\uff0c\u6ca1\u5565\u53ef\u8bf4\u3002<\/p>\n<pre class=\"lang:c++ decode:true \">#include &lt;iostream&gt;\nusing namespace std;\nstruct RecordNode\n{\n\t\/\/\u5b58\u653e\u5355\u4e2a\u5b66\u751f\u6570\u636e\u7684\u94fe\u8868\u8282\u70b9\n\tint studentID;\n\tint results[4];\t\/\/0-A, 1-C, 2-M, 3-E\n\tRecordNode* nextNode;\n\tRecordNode(int sid, int c, int m, int e, int a)\n\t{\n\t\tstudentID = sid;\n\t\tresults[0] = a;\n\t\tresults[1] = c;\n\t\tresults[2] = m;\n\t\tresults[3] = e;\n\t\tnextNode = NULL;\n\t}\n};\nRecordNode* rootNode = NULL;\nRecordNode* getNodePointer(int studentID)\n{\n\t\/\/\u6ca1\u6709\u5219\u8fd4\u56deNULL\n\tRecordNode* currNode = rootNode;\n\twhile (currNode != NULL)\n\t{\n\t\tif (currNode-&gt;studentID == studentID)\n\t\t\treturn currNode;\n\t\tcurrNode = currNode-&gt;nextNode;\n\t}\n\treturn currNode;\n}\nvoid getRankInMatrix(int studentID, int* ranks)\n\/\/\u4ece\u77e9\u9635\u4e2d\u5f97\u5230\u67d0\u4eba\u7684all\u6392\u4f4d\n\/\/(subj:  0-C, 1-M, 2-E, 3-A)\n{\n\t\/\/int ranks[4] = { 1, 1, 1, 1 };\n\tRecordNode* node = getNodePointer(studentID);\n\tif (node == NULL)\n\t{\n\t\t\/\/ranks = NULL;\n\t\t\/\/delete ranks;\n\t\tranks[0] = -1;\n\t\treturn;\n\t}\n\tint* results = node-&gt;results;\t\/\/\u6240\u6709\u8bfe\u7684\u6210\u7ee9\n\tRecordNode* opNode = rootNode;\n\twhile (opNode != NULL)\n\t{\n\t\t\/\/\u904d\u5386\n\t\tfor (int subj = 0; subj &lt; 4; subj++)\n\t\t{\n\t\t\t\/\/subjects\n\t\t\tif (opNode-&gt;results[subj] &gt; results[subj])\n\t\t\t\tranks[subj] ++;\n\t\t}\n\t\topNode = opNode-&gt;nextNode;\n\t}\n\t\/\/return ranks;\n}\nchar ACME[] = \"ACME\";\nint main()\n{\n\tint M, N;\n\tcin &gt;&gt; N &gt;&gt; M;\n\tRecordNode* opNode = rootNode;\n\tfor (int i = 0; i &lt; N; i++)\n\t{\n\t\tint sid, c, m, e, a;\n\t\tcin &gt;&gt; sid &gt;&gt; c &gt;&gt; m &gt;&gt; e;\n\t\ta = (int)(((c + m + e) \/ 3.0) + 0.5); \/\/\u56db\u820d\u4e94\u5165\n\t\tif (opNode == NULL)\n\t\t{\n\t\t\t\/\/\u65b0\u5efa\u6839\u8282\u70b9\n\t\t\topNode = new RecordNode(sid, c, m, e, a);\n\t\t\trootNode = opNode;\n\t\t\tcontinue;\n\t\t}\n\t\tRecordNode *currNode = new RecordNode(sid, c, m, e, a);\n\t\topNode-&gt;nextNode = currNode;\n\t\topNode = opNode-&gt;nextNode;  \/\/move forward\n\t}\n\tfor (int i = 0; i &lt; M; i++)\n\t{\n\t\tint sid;\n\t\tcin &gt;&gt; sid;\n\t\tint ranks[] = { 1, 1, 1, 1 };\n\t\tgetRankInMatrix(sid, ranks);\n\t\tif (ranks[0] == -1)\n\t\t{\n\t\t\tcout &lt;&lt; \"N\/A\";\n\t\t\tif (i &lt; M - 1)\n\t\t\t\tcout &lt;&lt; endl;\n\t\t\tcontinue;\n\t\t}\n\t\tint bestRank = ranks[0];\n\t\tint bestRankSubj = 0;\n\t\tfor (int x = 1; x &lt; 4; x++)\n\t\t{\n\t\t\tif (ranks[x] &lt; bestRank)\n\t\t\t{\n\t\t\t\tbestRank = ranks[x];\n\t\t\t\tbestRankSubj = x;\n\t\t\t}\n\t\t}\n\t\tcout &lt;&lt; bestRank &lt;&lt; \" \" &lt;&lt; ACME[bestRankSubj];\n\t\tif (i &lt; M - 1)\n\t\t\tcout &lt;&lt; endl;\n\t}\n\treturn 0;\n}<\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C &#8211; C Programming Language, M &#8211; Mathematics (Calculus or Linear Algebra), and E &#8211; English. At the mean time, we encourage students by emphasizing on their best ranks &#8212; that is, among the four ranks [&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],"tags":[84],"class_list":["post-1310","post","type-post","status-publish","format-standard","hentry","category-study","tag-pat"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1310","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=1310"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1310\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}