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
 
 
/*
    1、 输入数据,并且累计 第i篇论文 被引用的次数。
	2、 把人名相同的放在一起 ,当相同时引用次数排降序
    3、处理数据。把不同的人名存放,把同一人的论文前面编号,并用编号与引用次数比较,如果编号小于等于次数,num就加一次
	4、输出人名,h指数
*/
#include<iostream> 
#include<malloc.h>
#include<string>
#include<cstdio>
using namespace std;
struct str
{
   char a[25];      //作者名
   char b[105];    //论文
   int flag;      //  被引用次数
};
struct td
{
   char name[25];
   int num;
};
int main()
{
   int n,i,j,temp=0,p=0,k,h;
   struct str st[104];      //存放原始数据
   struct td  TT[104];       //要输出的数据
   char s[25];
   while(cin>>n&&n)
   {   
	   temp=0;

      for(i=1;i<=n;i++)
	  {   
		  cin>>st[i].a;    //  作者名
	       st[i].flag=0;   //  论文被引用的次数赋初值0
	  }

	  for(i=1;i<=n;i++)
		for(j=1;j<=n;j++) 
			cin>>st[i].b[j];    //  论文

	  for(i=1;i<=n;i++)
		  for(j=1;j<=n;j++)
			  if( st[i].b[j]=='1' && (i!=j))   // 1表示引用   不能引用本身  
                  st[j].flag+=1;   //累计被引用的次数

        for(i=1;i<n;i++)
		   for(j=i+1;j<=n;j++)
             if(strcmp(st[i].a,st[j].a)<0)    //  把作者名 按 降序 排列
			   {
			      strcpy(s,st[i].a);   strcpy(st[i].a,st[j].a);   strcpy(st[j].a,s);
				  temp=st[i].flag;   st[i].flag=st[j].flag;   st[j].flag=temp;
			   }
			 else   if(strcmp(st[i].a,st[j].a)==0)   // 人名相同
				      if(st[i].flag<st[j].flag)      //  论文引用次数排降序
					   {
					      strcpy(s,st[i].a);   strcpy(st[i].a,st[j].a);   strcpy(st[j].a,s);
				          temp=st[i].flag;   st[i].flag=st[j].flag;   st[j].flag=temp;
					   }

             //处理数据
          for(i=1,k=1;i<=n;i=j)
		  {       p=1; 
	             TT[k].num=0;
		    for(j=i;  strcmp(st[i].a,st[j].a)==0  ;j++)				  
				if(p<=st[j].flag)  
				  {  
					  TT[k].num++;   
				      p++; 
				}
			strcpy(TT[k].name,st[i].a);
			k++;
		  }

             h=k-1;
		  for(i=1;i<h;i++)
			  for(j=i+1;j<=h;j++)
				   if(TT[i].num<TT[j].num)      //  论文引用次数排降序
					   {
					      strcpy(s,TT[i].name);   strcpy(TT[i].name,TT[j].name);   strcpy(TT[j].name,s);
				          temp=TT[i].num;         TT[i].num=TT[j].num;             TT[j].num=temp;
					   }
				   else if(TT[i].num==TT[j].num)      // 引用次数相同
				   {  if(strcmp(TT[i].name,TT[j].name)>0)    //  把作者名  按 升序 排列
						   {
			                 strcpy(s,TT[i].name);   strcpy(TT[i].name,TT[j].name);   strcpy(TT[j].name,s);
				             temp=TT[i].num;         TT[i].num=TT[j].num;              TT[j].num=temp;
						   }
				   }

        for(i=1;i<k;i++)
           printf("%s %d\n",TT[i].name,TT[i].num);
	    cout<<endl;
   }
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值