hdu 2115 I Love This Game

简介:

http://acm.hdu.edu.cn/showproblem.php?pid=2115
注意两点:
1:输出格式;
2:结构体排序

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct sa
{
    char name[55];
    int a;
    int b;
    int num;
    char ch;
}data[15];
int cmp(sa x,sa y)
{
    if(x.a != y.a)
        return x.a < y.a;
    else if(x.b != y.b)
        return x.b < y.b;
    else
        return strcmp(x.name,y.name)<0;
}
int main()
{
    int m,cas=1;
    bool flag=0;
    while(cin>>m,m)
    {
        if(flag)
            cout<<endl;
        flag=1;
        for(int i=0; i<m; i++)
         cin>>data[i].name>>data[i].a>>data[i].ch>>data[i].b;
        sort(data,data+m,cmp);
        cout<<"Case #"<<cas++<<endl;
        int sum=1;
        data[0].num=1;
        for(int i=1; i<m; i++)
        {
            if(data[i].a == data[i-1].a && data[i].b == data[i-1].b)
               data[i].num=sum;
            else
            {
                data[i].num=sum;
                sum=i+1;
                data[i].num=i+1;
            }
        }
        for(int i=0; i<m; i++)
            cout<<data[i].name<<" "<<data[i].num<<endl;
    }
    return 0;
}
目录
相关文章
|
6月前
|
算法
uva 10891 game of sum
题目链接 详细请参考刘汝佳《算法竞赛入门经典训练指南》 p67
14 0
|
算法 索引
LeetCode 55. Jump Game
给定一个非负整数数组,您最初定位在数组的第一个索引处。 数组中的每个元素表示该位置的最大跳转长度。 确定您是否能够到达最后一个索引。
71 0
LeetCode 55. Jump Game
HDOJ(HDU) 2115 I Love This Game(排序排序、、、)
HDOJ(HDU) 2115 I Love This Game(排序排序、、、)
71 0
LeetCode - 45. Jump Game II
45. Jump Game II  Problem's Link  ---------------------------------------------------------------------------- Mean:  给定一个数组a,玩家的初始位置在idx=0,玩家需要到达的位置是idx=a.
918 0
|
机器学习/深度学习 算法
|
机器学习/深度学习
|
C++ Python
[LeetCode] Jump Game II
This problem has a nice BFS structure. Let's illustrate it using the example nums = [2, 3, 1, 1, 4] in the problem statement.
885 0