Description
Beijing airlines will hold the fourth Program Design Competition. contestants can register online. However, some students may enter another registration form due to incorrect information during registration, which may cause some trouble for the participating organizers. So the competition organizer thoughtCount the number of registrants per studentTo manually check the registration information.
Input
This question contains multiple groups of test data. The maximum number of first-row registration numbers, which can be 1000. Next, each row has a student ID, which is an eight-digit student ID for Beihang undergraduates. The input data ends with 0.
Output
Input data for each group,The first occurrence order of the student ID in the input dataAnd the number of occurrences of the student ID, which are separated by spaces.There is a blank line between each two groups of data..
Example input 7
35211312
36211625
35211425
35211425
35211425
36211625
36211625
2
35211425
35211425
0 sample output
35211312 1
36211625 3
35211425 3
35211425 2
Solution:
This is a simulated question. The student ID that appears for the first time is recorded and stored in an array. Then, the student ID that appears later is compared with the student ID in the array to determine the number of times.
#include<stdio.h>#include<string.h>main(){int te;int number;int i,j;char a[1000][100];int count[1000];scanf("%d",&number);getchar();while(number!=0){for(i=0;i<1000;i++)count[i]=0;for(te=0;te<number;te++){ scanf("%s",&a[te]);}for(i=0;i<number;i++)for(j=i+1;j<number;j++)if(strcmp(a[i],a[j])==0&&a[j][0]!='*'&&a[i][0]!='*'){ count[i]++; a[j][0]='*';}for(i=0;i<number;i++){ if(a[i][0]!='*'){ for(j=0;a[i][j]!='\0';j++) printf("%c",a[i][j]); printf(" %d\n",count[i]+1);}} printf("\n");scanf("%d",&number);getchar();}}