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.
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.
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.
Output a blank line after each scenario.
Sample Input
4 Peter Peter Bob Bob 0000 1000 1100 0100 0
其中1代表引用,0代表没引用;
第n列就代表第n篇文章;
# include<cstdio> # include<iostream> # include<cstring> # include<algorithm> using namespace std; struct H //定义结构体; { string s; int n; }h[110],hh[110]; int cmp1(H n,H m) //比较函数 { if(n.s!=m.s) return n.s<m.s; else return n.n>m.n; } int cmp2(H n,H m) { if(n.n!=m.n) return n.n>m.n; else return n.s<m.s; } int main() { //freopen("a.txt","r",stdin); int n; while(cin>>n&&n) { int i,j,cnt=0; char a[110][110]; for(i=1;i<=n;i++) { cin>>h[i].s; h[i].n=0; //置零; } for(i=1;i<=n;i++) for(j=1;j<=n;j++) cin>>a[i][j]; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(a[i][j]=='1'&&(i!=j)) h[j].n++; sort(h+1,h+n+1,cmp1); //排序,将同一作者排在一起,引用次数按降序(即从大到小) for(i=1;i<=n;i=j) //求H因子; { int sum=0,m=1; for(j=i;h[i].s==h[j].s;j++) { if(m<=h[j].n) { m++; sum++; } } hh[++cnt].s=h[i].s; hh[cnt].n=sum; } sort(hh+1,hh+cnt+1,cmp2); //排序输出,先排h因子大小,再排作者; for(i=1;i<=cnt;i++) cout<<hh[i].s<<' '<<hh[i].n<<endl; cout<<endl; } return 0; }