H-index因子

Problem Description

Paper quality and quantity have long been used to measure a research's scientific productivity and scientific impact. Citation, which is the total times a paper has been cited, is a common means to judge importance of a paper. However, with all these factors varying, a collegiate committee has problems when judging which research is doing better. For this reason, H-index is proposed and now widely used to combine the above factors and give accurate judgement. H-index is defined as:
A scientist has index h if h of [his] Np papers have at least h citations each, and the other(Np-h) papers have at most h citations each.
In other words, a scholar with an index of h has published h papers each of which has been cited by others at least h times. Note that H-index is always an integer. It's said that achiveing H-index of 18 means one is fully quality to be a professor, and H-index of 45 or higher could mean membership in the United States Academy of Sciences.
You are to calculate the H-index for all the researchers in the list, base on the given information.

Input

There are multiple scenarios in the input, terminated by a single zero(0).
Each of the scenarios begin with an integer N(1<=N<=100), means that there are N papers. N lines follow, each contain a string(not exceeding 20 characters long), representing the author of the corresponding paper, without white spaces in-between. Though it would be common for one paper written by several authors, there would be exactly one author of each of these papers. Finally, there are N lines of strings, containing '0's and '1's. If the j-th character in the i-th line is '1', it means the i-th paper cites the j-th paper. A paper could never cite itself.

Output

For each scenario, output as many lines as the number of authors given. Each line contains the author's name and his H-index. The list should be sorted first by H-index in descending order, than by name in alphabetic order(Actually, ASCII order. So 'B' is prior to 'a').
Output a blank line after each scenario.

Sample Input

4
Peter
Peter
Bob
Bob
0000
1000
1100
0100
0

Sample Output

Peter 2
Bob 0

Author

HYNU


/*
思路:引用,不能引用文章自己本身,但可以引用同一个作者的其他文章(引用的是1,没有引用是0)
统计引用次数后,对同一个作者的引用次数排降序,再编号(把同一个人名放在一起)
比较编号<引用次数,H指数加一次
再对H指数排降序,对作者名字排升序
*/
#include<cstdio>
#include<string.h>
#include<iostream>
using namespace std;
struct msc//存放原来的
{
    char s[21];//作者
    char b[104];//论文
    int flot;//存引用次数
};
struct mmx//存放的是统计出每个作者,和h指数
{
    char str[21];//作者
    int sum;//h指数
};
int main()
{
    msc a[104];
    int n, j, i, m, num, k, w, h;
    char t[21];
    while(scanf("%d", &n) != EOF && n)
    {
        for(i = 1; i <= n; i++)
        {
            cin >> a[i].s;
            a[i].flot = 0;
        }
        for(i = 1; i <= n; i++)
            for(j = 1; j <= n; j++)
                cin >> a[i].b[j];


        for(i = 1; i <= n; i++) //统计引用次数
            for(j = 1; j <= n; j++)
                if(a[i].b[j] == '1' && (i != j))
                    a[j].flot++;


        for(i = 1; i < n; i++) //排序,按作者名排序,再按引用次数排序,降序
        {
            for(j = i + 1; j <= n; j++)
            {
                if(strcmp(a[i].s, a[j].s) < 0)
                {
                    strcpy(t, a[i].s);
                    strcpy(a[i].s, a[j].s);
                    strcpy(a[j].s, t);
                    w = a[i].flot;
                    a[i].flot = a[j].flot;
                    a[j].flot = w;
                }
                else if(strcmp(a[i].s, a[j].s) == 0)
                {
                    if(a[i].flot < a[j].flot)
                    {
                        w = a[i].flot;
                        a[i].flot = a[j].flot;
                        a[j].flot = w;
                        strcpy(t, a[i].s);
                        strcpy(a[i].s, a[j].s);
                        strcpy(a[j].s, t);
                    }
                }
            }
        }


        mmx x[104];
        k = 1;
        for(i = 1; i <= n; i = j) //统计h指数:把每位作者的论文的引用次数排序之后,从1开始编号,然后引用次数和编号比较
        {
            m = 1;
            num = 0;


            for(j = i; strcmp(a[i].s, a[j].s) == 0; j++)
            {
                if(m <= a[j].flot)
                {
                    m++, num++;   //编号<次数。。h指数加一次
                }
            }
            strcpy(x[k].str, a[i].s);
            x[k].sum = num;
            k++;
        }
        h = k - 1;
        for(i = 1; i < h; i++) //排序,按h指数排序,降序,再按作者名排序,排升序
        {
            for(j = i + 1; j <= h; j++)


            {
                if(x[i].sum < x[j].sum)
                {
                    strcpy(t, x[i].str);
                    strcpy(x[i].str, x[j].str);
                    strcpy(x[j].str, t);
                    w = x[i].sum;
                    x[i].sum = x[j].sum;
                    x[j].sum = w;
                }
                else if(x[i].sum == x[j].sum)
                {
                    if(strcmp(x[i].str, x[j].str) > 0)
                    {
                        strcpy(t, x[i].str);
                        strcpy(x[i].str, x[j].str);
                        strcpy(x[j].str, t);
                        w = x[i].sum;
                        x[i].sum = x[j].sum;
                        x[j].sum = w;
                    }
                }
            }
        }
        for(i = 1; i < k; i++) //输出
            printf("%s %d\n", x[i].str, x[i].sum);
        cout << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值