codeup- group statistics

2066: group statistics

Time Limit: 1 Sec  Memory Limit: 32 MB
Submit: 2038  Solved: 498
[Submit][Status][Web Board][Creator:Imported]

Description

To enter a number, then enter its packet, the packet according to the number of occurrences counted and output, see examples.

Input

Input of the first row represents a sample number m, for each sample, the number n of the number of the first row, the next two lines respectively, the number n, the number n of first line, second line number n the packet corresponding to each row number, n does not exceed 100.

Output

M output lines, see sample format, in ascending row.

Sample Input

1
7
3 2 3 8 8 2 3
1 2 3 2 1 3 1

Sample Output

1={2=0,3=2,8=1}
2={2=1,3=0,8=1}
3={2=1,3=1,8=0}

. 1 #include <stdio.h>
 2  
. 3  // Note that, the number of groups is not necessarily continuous 
. 4  
. 5  struct Number The {
 . 6      int zu;
 . 7      int Val;
 . 8  };
 . 9  
10  int main () {
 . 11      int m, n-;
 12 is      the while (Scanf ( " % D " !, & m) = the EOF) {
 13 is          the while (M-- ) {
 14              Scanf ( " % D " , & n-);
 15              Number The NUM [n-];
 16              int= max 0 , MAXN = 0 ; // number of groups of records appear 
. 17              for ( int I = 0 ; I <n-; I ++ ) {
 18 is                  Scanf ( " % D " , & (NUM [I] .val));
 . 19                  IF (NUM [I] .val> MAXN) {
 20 is                      MAXN = NUM [I] .val;
 21 is                  }
 22 is              }
 23 is              for ( int I = 0 ; I <n-; I ++ ) {
 24                  Scanf ( " % D ", &(num[i].zu));
25                 if(num[i].zu > max){
26                     max = num[i].zu;
27                 }
28             }
29             int a[max+1][maxn+1];
30             //初始化不可以用a[max][maxn] = {0}; 
31             for(int i=0; i<=max; i++){
32                 for(int j=0; j<=maxn; j++){
33                     a[i][j] = 0;
34                 }
35             }
36             for(int i=0; i<n; i++){
37                 a[0][num[i].val] = 1;
38                 a[num[i].zu][0] = 1;
39                 a[num[i].zu][num[i].val]++;
40             }
41             for(int i=1; i<=max; i++){
42                 if(a[i][0]==0){
43                     continue;
44                 }
45                 printf("%d={", i);
46                 for(int j=0; j<=maxn; j++){
47                     if(a[0][j]==1){
48                         printf("%d=%d", j, a[i][j]);
49                         if(j!=maxn){
50                             printf(",");
51                         }
52                     }
53                 }
54                 printf("}\n");
55             }
56         }
57     }
58     return 0;
59 }

Guess you like

Origin www.cnblogs.com/heyour/p/12149895.html