Song Jiang ' s rank listTime
limit:2000/1000 MS (java/others) Memory limit:512000/512000 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0
Problem Description
Input
There is no more than test cases. For each test case: The first line was an integer n (0<n<200), indicating that there was N outlaws. Then N lines follow. Each line contains a string S and a integer K (0<k<300), meaning an outlaw ' s name and the number of enemies he/she h Ad killed. A name consists only letters, and its length is between 1 and (inclusive). Every name is unique. The next line is a integer m (0<m<200), indicating that there is M queries. Then M queries follow. Each query was a line containing an outlaw ' s name. The input ends with n = 0
Output
For each test case, print the Rank list first. For the contains a outlaw ' s name and the number of enemies he killed.
Sample Input
5WuSong 12LuZhishen 12SongJiang 13LuJunyi 1HuaRong 155WUSONGLUJUNYILUZHISHENHUARONGSONGJIANG0
Sample Output
Huarong 15SongJiang 13LuZhishen 12WuSong 12LuJunyi 13 25312
Simple question:
Not much to say (tears)
Note that the sorting function cannot be used with strcmp, I remember using it before, and I guess I'm mistaken, eh?
AC Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < cstdlib> #include <cmath> #include <stack> #include <queue> #define LL long long#define max3 (a,b,c) Max (A,max (b,c)) #define MIN3 (a,b,c) min (a,min (b,c)) using namespace Std;struct node{char name[105]; int num; int major, Minor;} Out[210];bool CMP (Node A, Node B) {if (a.num!=b.num) return a.num>b.num; else for (int i=0;;) {if (A.name[i]!=b.name[i]) return a.name[i]<b.name[i]; else i++; }}int Main () {int n, m; while (scanf ("%d", &n), N) {for (int i=0; i<n; i++) {scanf ("%s%d", Out[i].name, &o Ut[i].num); Out[i].major=1; Out[i].minor=1; } sort (out, out+n, CMP); for (int i=0; i<n; i++) {printf ("%s%d\n", Out[i].name, Out[i].num); } int rank = 1; for (int i=1; i<n; i++) { rank++; if (out[i].num==out[i-1].num) {out[i].major = Out[i-1].major; Out[i].minor = out[i-1].minor+1; } else Out[i].major = rank; } scanf ("%d", &m); for (int i=0; i<m; i++) {char b[105]; scanf ("%s", b); for (int j=0; j<n; J + +) {if (strcmp (b, Out[j].name) ==0) {if (out[j].minor==1) printf ("%d\n", out[j].major); else printf ("%d%d\n", Out[j].major, Out[j].minor); Break }}}} return 0;}
2014ACM/ICPC Guangzhou Division E question (water ~)