Solution Idea

50100. Impact Factor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "compute.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int numJournal = 0;
char *journalList[1024] = {};
int citationCount[1024] = {};
int publishCount[1024] = {};
typedef struct {
    char *journalName;
    int citationCount;
    int publishCount;
} Pack;
int journalFind(char *name) {
    for (int i = 0; i < numJournal; i++)
        if(strcmp(name, journalList[i])==0)
            return i;
    return -1;
}
int cmp(const void *a, const void *b) {
    Pack *aa = (Pack *)a;
    Pack *bb = (Pack *)b;
    return strcmp(aa->journalName, bb->journalName);
}
void compute(paper P[], int N) {
    for (int i = 0; i < N; i++)
        if (journalFind(P[i].journalName)==-1) {
            journalList[numJournal] = P[i].journalName;
            publishCount[numJournal] = 1;
            numJournal++;
        }
        else
            publishCount[journalFind(P[i].journalName)]++;
    for (int i = 0; i < N; i++) {
        int numCite = P[i].numCitedPaper;
        for (int j = 0; j < numCite; j++) {
            int citeId = P[i].citedPaperIndex[j];
            citationCount[journalFind(P[citeId].journalName)]++;
        }
    }
    //Pack is used to sorting.
    Pack pack[1024] = {};
    for (int i = 0; i < numJournal; i++) {
        pack[i].journalName = journalList[i];
        pack[i].citationCount = citationCount[i];
        pack[i].publishCount = publishCount[i];
    }
    qsort(pack, numJournal, sizeof(Pack), cmp);
    for (int i = 0; i < numJournal; i++)
        printf("%s %d/%d\n", pack[i].journalName, pack[i].citationCount, pack[i].publishCount);
    return;
}

Discussion