Test instructions: Given n individuals, and their number is compared, starting from behind, if not long enough, add middle then than, until not, if the same than the name.
Analysis: The problem of water, it is needless to say.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < functional> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring># Include <set> #include <queue> #include <algorithm> #include <vector> #include <deque># Include <map> #include <cctype> #include <stack> #include <sstream>using namespace std; typedef Long Long ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f;const double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = 1e3 + 5;const int mod = 1e9 + 7;const char *mark = "+-*"; const INT DR [] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};int N, m;inline bool is_in (int r, int c) {return R >= 0 && R < n && C >= 0 && C < m;} inline int Min (int a, int b) {return a < b a:b;} inline int Max (int a, int b) {return a > b a:b;} struct node{string S; Vector<int> v;}; Node a[maxn];string s;bool CMP (const node &LHS, const node &RHS) {int i = lhs.v.size ()-1, J = rhs.v.size ()-1; while (true) {if (i >= 0 && J >= 0) {if (Lhs.v[i]! = Rhs.v[j]) return lhs.v[i] > rhs.v[ J]; } else if (I >= 0) {if (lhs.v[i]! = 1) return lhs.v[i] > 1; } else if (J >= 0) {if (rhs.v[j]! = 1) return rhs.v[j] < 1; }--------j; if (I < 0 && J < 0) break; } return LHS.S < RHS.S;} int main () {while (scanf ("%d", &n) = = 1) {for (int i = 0; i < n; ++i) {a[i].v.clear (); Cin >> A[i].s; A[i].s.pop_back (); while (Cin >> s && s[0]! = ' C ') {if (s[0] = = ' u ') a[i].v.push_back (2); else if (s[0] = = ' m ') a[i].v.push_back (1); else A[i].v.push_back (0); }} sort (A, a+n, CMP); for (int i = 0; i < n; ++i) cout << a[i].s << Endl; } return 0;}
LA uvalive 7370 Classy (sort, compare)