#include <the iostream> #include < String > #include <CString> the using namespace STD; int max_ = 0 ; // every time the count increases, it is judged that the count increases at this time is not the maximum, max_ stored current maximum int f = 0 ; // flags What parallel madman int N; int samecount = 0 ; // tied for the number of wild char the Result [ 20 ]; // madman phone number typedef unsigned Long Long Index; Index Hash ( const char * key,Long Long tableSize) // "Data structure and algorithm analysis -C Language Description" Hash function { unsigned Long Long hashval = 0 ; the while (* (+ Key . 4 !) = 0 ) // Why 3 and 4 to 6 you can be AC? ? ? ? = hashval (<< hashval . 5 ) * + Key ++; // * (Key ++) return hashval% tableSize; } struct num_node { char NUM [ 100 ]; int COUNT; struct num_node * Next; }; typedef struct num_node* node_ptr; node_ptr* createtable(int size) { node_ptr* H = new node_ptr[size]; for (int i = 0; i < size; i++) { H[i] = new struct num_node; H[i]->count = 0; if (H[i] != NULL) H[i]->next = NULL; } return H; } void insert(charSTR *, * node_ptr H) { int In Flag = 0 ; // if this number flag table already exists int hashval the Hash = (STR, 2 * ; N) node_ptr S = H [hashval]; the while (S-> Next! NULL =) // first node is not used to store data { S = S-> Next; IF (strcmp (STR, S->! ) NUM) { In Flag = . 1 ; S -> COUNT ++ ; IF (S-> COUNT > max_) // whenever count change determination count is not the current maximum { strcpy(result, s->num); max_ = s->count; } break; } } if (flag == 0) { node_ptr temp = new num_node; temp->next = NULL; strcpy(temp->num, str); temp->count = 1; if (temp->count > max_) { strcpy(result, temp->num); max_ = temp->count; } s->next = temp; } } void judge(node_ptr* H) { for (int i = 0; i < 2 * N; i++) { node_ptr s = H[i]; while (s->next != NULL) { s = s->next; if (max_ == s->count and strcmp(result, s->num) != 0) { f = 1; samecount++; if (strcmp(s->num, result) < 0) { strcpy(result, s->num); } } } } } int main() { cin >> N; node_ptr* H = createtable(2 * N); for (int i = 0; i < N; i++) { char str1[20]; cin >> str1; INSERT (str1, H); char str2 [ 20 is ]; CIN >> str2; INSERT (str2, H); } Judge (H); // get longer parallel to the case where there is no maximum premise Analyzing IF (F == 0 ) COUT << Result << " " << max_; the else IF (F == . 1 ) COUT << Result << " " << max_ << " " << samecount; return 0 ; }