fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 100
  4. typedef struct {
  5. char name[256];
  6. unsigned char sex;
  7. unsigned char age;
  8. } PERSONAL_DATA;
  9.  
  10. int main()
  11. {
  12. PERSONAL_DATA d[N];
  13. int cnt[100] = {0};
  14. for (int i = 0; i < N; ++i) {
  15. sprintf(d[i].name, "%d", rand());
  16. d[i].sex = rand() % 100 < 50 ? 'F' : 'M';
  17. d[i].age = rand() % 80 + 10;
  18. }
  19. printf("input data:\n");
  20. printf("%-20s %s %s\n", "name", "sex", "age");
  21. for (int i = 0; i < N; ++i)
  22. printf("%-20s %-3c %d\n", d[i].name, d[i].sex, d[i].age);
  23.  
  24. for (int i = 0; i < N; ++i)
  25. cnt[d[i].age]++;
  26.  
  27. printf("\noutput result:\n");
  28. for (int i = 0; i < N; ++i)
  29. if (cnt[i] > 1) {
  30. printf("\nage = %d, count = %d\n", i, cnt[i]);
  31. for (int j = 0; j < N; ++j)
  32. if (d[j].age == i)
  33. printf("name = %s\n", d[j].name);
  34. }
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
input data:
name                 sex age
1804289383           M   67
1714636915           M   25
719885386            M   19
1189641421           M   37
783368690            M   13
1967513926           F   76
304089172            F   21
521595368            M   39
336465782            F   72
233665123            M   25
1101513929           F   32
635723058            M   17
1059961393           M   61
1656478042           F   23
859484421            F   34
756898537            M   14
149798315            M   23
184803526            M   30
1911759956           M   72
42999170             M   11
511702305            F   54
1827336327           F   35
805750846            F   43
1433925857           F   65
939819582            F   24
1548233367           F   54
1374344043           M   57
356426808            M   68
1780695788           M   53
1918502651           M   89
2053999932           M   86
1843993368           F   22
855636226            M   24
1956297539           M   20
2040651434           M   37
1892066601           M   32
1330573317           M   22
660260756            F   50
402724286            F   35
894429689            F   69
221558440            F   41
1633108117           M   21
1469834481           M   79
791698927            M   26
1255179497           M   36
1572276965           F   53
352406219            F   18
2040332871           F   39
378409503            F   40
1573363368           F   85
1373226340           F   46
289700723            F   15
150122846            M   51
1760243555           M   58
111537764            F   11
438792350            M   70
2142757034           M   54
155324914            M   26
1275373743           M   77
841148365            M   26
771151432            M   47
971899228            M   57
1139901474           F   68
2130794395           F   47
1605908235           M   68
1605894428           F   61
1875335928           F   66
1597322404           F   13
1432114613           F   56
1782436840           F   28
1395235128           M   19
492067917            F   46
706043324            F   40
1359512183           M   69
1096689772           F   54
1172755590           F   69
1012502954           M   79
968338082            F   74
933110197            F   85
1285228804           F   61
1450573622           F   29
654887343            F   58
1335354340           F   41
1494613810           F   51
745425661            F   88
1346811305           F   26
1590079444           F   52
1470503465           F   66
1143408282           M   54
1884167637           M   34
238962600            F   22
1273911899           M   40
1665947468           M   23
407487131            M   60
1776808933           M   30
937370163            M   71
1642548899           M   89
1472713773           F   78
2025187190           M   56
437116466            M   70

output result:

age = 11, count = 2
name = 42999170
name = 111537764

age = 13, count = 2
name = 783368690
name = 1597322404

age = 19, count = 2
name = 719885386
name = 1395235128

age = 21, count = 2
name = 304089172
name = 1633108117

age = 22, count = 3
name = 1843993368
name = 1330573317
name = 238962600

age = 23, count = 3
name = 1656478042
name = 149798315
name = 1665947468

age = 24, count = 2
name = 939819582
name = 855636226

age = 25, count = 2
name = 1714636915
name = 233665123

age = 26, count = 4
name = 791698927
name = 155324914
name = 841148365
name = 1346811305

age = 30, count = 2
name = 184803526
name = 1776808933

age = 32, count = 2
name = 1101513929
name = 1892066601

age = 34, count = 2
name = 859484421
name = 1884167637

age = 35, count = 2
name = 1827336327
name = 402724286

age = 37, count = 2
name = 1189641421
name = 2040651434

age = 39, count = 2
name = 521595368
name = 2040332871

age = 40, count = 3
name = 378409503
name = 706043324
name = 1273911899

age = 41, count = 2
name = 221558440
name = 1335354340

age = 46, count = 2
name = 1373226340
name = 492067917

age = 47, count = 2
name = 771151432
name = 2130794395

age = 51, count = 2
name = 150122846
name = 1494613810

age = 53, count = 2
name = 1780695788
name = 1572276965

age = 54, count = 5
name = 511702305
name = 1548233367
name = 2142757034
name = 1096689772
name = 1143408282

age = 56, count = 2
name = 1432114613
name = 2025187190

age = 57, count = 2
name = 1374344043
name = 971899228

age = 58, count = 2
name = 1760243555
name = 654887343

age = 61, count = 3
name = 1059961393
name = 1605894428
name = 1285228804

age = 66, count = 2
name = 1875335928
name = 1470503465

age = 68, count = 3
name = 356426808
name = 1139901474
name = 1605908235

age = 69, count = 3
name = 894429689
name = 1359512183
name = 1172755590

age = 70, count = 2
name = 438792350
name = 437116466

age = 72, count = 2
name = 336465782
name = 1911759956

age = 79, count = 2
name = 1469834481
name = 1012502954

age = 85, count = 2
name = 1573363368
name = 933110197

age = 89, count = 2
name = 1918502651
name = 1642548899