自己写的。C语言。题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
#include<stdio.h>
int main() {
    int NumOfCandidate, NumOfVoters, NumOfInvalid = 0, i, j, k;
    char VoterTemp[100];
    scanf("%d", &NumOfCandidate);
    char Candidates[NumOfCandidate][100];
    int Votes[NumOfCandidate];
    for (i = 0; i < NumOfCandidate; i++) {
        scanf("%s", Candidates[i]);
        Votes[i] = 0;
    }
    scanf("%d", &NumOfVoters);
    for (i = 0; i < NumOfVoters; i++) {
        scanf("%s", VoterTemp);
        for (j = 0; j < NumOfCandidate; j++) {
            k = 0;
            while (VoterTemp[k] != '\0' && Candidates[j][k] != '\0' &&
                    VoterTemp[k] == Candidates[j][k]) {
                k++;
            }
            if (VoterTemp[k] == '\0' && Candidates[j][k] == '\0') {
                Votes[j]++;
                j = NumOfCandidate ;
            }
        }
        if (j == NumOfCandidate) {
            NumOfInvalid++;
        }
    }
    for (i = 0; i < NumOfCandidate; i++) {
        printf("%s : %d\n", Candidates[i], Votes[i]);
    }
    printf("Invalid : %d\n", NumOfInvalid);
    return 0;
}
 深信服公司福利 737人发布
深信服公司福利 737人发布 查看19道真题和解析
查看19道真题和解析