Uvalive 7077-song Jiang ' s rank list (analog)

Source: Internet
Author: User
Tags strcmp

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=5085

The main idea: to give n individuals and each person's name s and the enemy he can kill number m, the number of these people can be killed by ranking and output, m query, each query output this person's two rankings,

One was that he was before his rank (he could not kill, note: He could not kill the number of people equal to his killing enemies) + 1, one was his rank before the number of enemies with whom he kills equals + 1

#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<algorithm>using namespacestd;Const intN = About;structst{intm, add, same, F; Chars[ -];} Node[n], a[n];intcmpConst void*a,Const void*b) {St*S1 = (ST *) A, *S2 = (ST *) b; if(S1->m! = s2->m)returnS2->m-s1->m; Else        returnstrcmp (S1->s, s2->R); //Order by Dictionary}intMain () {intN, I, J, M;  while(SCANF ("%d", &N), N) { for(i =0; I < n; i++) {scanf ("%s%d", Node[i].s, &node[i].m); Node[i].same= NODE[I].F =0; } qsort (node, n,sizeof(node[0]), CMP); scanf ("%d", &m);  for(i =1; I <= m; i++) {scanf ("%s", A[I].S);  for(j =0; J < N; J + +)            {                if(strcmp (A[I].S, node[j].s) = =0) A[i].add=J; }        }//A[i].add is the first person's rank, ranking starting from No. 0 Place         for(i =0; I < n-1; i++)        {             for(j = i +1; J < N; J + +)            {                if(NODE[I].M = =node[j].m) Node[j].same++; }        }//Count The number of people he had killed before he ranked the enemy.         for(i =0; I < n; i++) printf ("%s%d\n", Node[i].s, NODE[I].M);  for(i =1; I <= m; i++)        {            if(Node[a[i].add].same >=1) printf ("%d%d\n", A[i].add-node[a[i].add].same +1, Node[a[i].add].same +1); Elseprintf ("%d\n", A[i].add-node[a[i].add].same +1); }    }    return 0;}

Uvalive 7077-song Jiang ' s rank list (analog)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.