hdu 2115 :I Love This Game(Presentation Error容易输出wrong)

#include<stdio.h>
#include<queue>
#include<iostream>
#include<string.h>
using namespace std;
struct node
{
    char s[150];
    int level;
    int k;
    friend bool operator <(node n1,node n2)
    {
        if(n1.level==n2.level)     
        return strcmp(n2.s,n1.s)<0;
        else  
        return n1.level>n2.level;
    }
};
int main()
{
    int n;
    int a,b,d;
    char c[150];
    node temp;
    int m=0;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        m++;
        priority_queue<node>p;
        while(n--)
        {
            scanf("%s %d:%d",c,&a,&b);
            d=a*60+b;
            temp.level=d;
            strcpy(temp.s,c);
            p.push(temp);
        }
        if(m!=1)printf("\n");
        int i=0;
        int jk=0,j=0;
        printf("Case #%d\n",m);//每组测试用例之间有空行
        while(!p.empty())
        {
            i++;
            if(i==1)printf("%s %d\n",p.top().s,i);
            else
            {
                if(jk==p.top().level)
                {
                    j++;
                    printf("%s %d\n",p.top().s,i-j);
                }
                else
                printf("%s %d\n",p.top().s,i);
            }
            jk=p.top().level;
            p.pop();
        }
        //printf("\n");//不能加在这,否则最后一行会多一行空行
    }
    return 0;
}

最近做水题 

              越发的体会到STL的强大(用的是优先队列)!

难题解决 :

        1.比较函数中的strcmp(n2.s,n1.s)<0第一次用;
2.最后名次的输出处理。
3.对比了别人的代码才知道这样输出。
原文地址:https://www.cnblogs.com/XDJjy/p/3001125.html