fork download
  1. #include <iostream>
  2. #include <unordered_map>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. unordered_map<int, int> cnt;
  9.  
  10. cin >> n;
  11. for (int i = 0; i < n; i++) {
  12. int a;
  13. cin >> a;
  14. cnt[a]++;
  15. }
  16.  
  17. int num = cnt.bucket_count();
  18. for (int i = 0; i < num; i++)
  19. cout << "bucket #" << i << " has " << cnt.bucket_size(i) << " elements." << endl;
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3468KB
stdin
100
1123 1453 696 1831 12 1189 1744 1031 1919 1951 339 1323 634 1057 1403 1577 510 148 1149 660 676 1168 476 61 344 1858 1933 39 1307 1559 956 672 132 685 27 830 1683 1815 566 1303 1841 1141 1697 15 1121 574 1779 1459 2 1405 524 906 676 447 1869 1745 956 1435 1958 1771 1536 673 1406 1343 333 1211 996 133 1294 1537 1330 1654 1703 289 1066 4 612 988 656 194 827 1385 1124 1250 1393 1510 1152 924 639 1555 1989 1503 1165 1953 795 356 818 899 285 1671 
stdout
bucket #0 has 1 elements.
bucket #1 has 1 elements.
bucket #2 has 1 elements.
bucket #3 has 0 elements.
bucket #4 has 1 elements.
bucket #5 has 0 elements.
bucket #6 has 0 elements.
bucket #7 has 0 elements.
bucket #8 has 0 elements.
bucket #9 has 0 elements.
bucket #10 has 1 elements.
bucket #11 has 0 elements.
bucket #12 has 2 elements.
bucket #13 has 1 elements.
bucket #14 has 0 elements.
bucket #15 has 2 elements.
bucket #16 has 0 elements.
bucket #17 has 1 elements.
bucket #18 has 0 elements.
bucket #19 has 0 elements.
bucket #20 has 0 elements.
bucket #21 has 0 elements.
bucket #22 has 1 elements.
bucket #23 has 0 elements.
bucket #24 has 1 elements.
bucket #25 has 0 elements.
bucket #26 has 0 elements.
bucket #27 has 1 elements.
bucket #28 has 0 elements.
bucket #29 has 0 elements.
bucket #30 has 0 elements.
bucket #31 has 1 elements.
bucket #32 has 0 elements.
bucket #33 has 0 elements.
bucket #34 has 1 elements.
bucket #35 has 0 elements.
bucket #36 has 1 elements.
bucket #37 has 1 elements.
bucket #38 has 0 elements.
bucket #39 has 1 elements.
bucket #40 has 1 elements.
bucket #41 has 0 elements.
bucket #42 has 2 elements.
bucket #43 has 0 elements.
bucket #44 has 0 elements.
bucket #45 has 0 elements.
bucket #46 has 0 elements.
bucket #47 has 0 elements.
bucket #48 has 0 elements.
bucket #49 has 1 elements.
bucket #50 has 1 elements.
bucket #51 has 0 elements.
bucket #52 has 0 elements.
bucket #53 has 0 elements.
bucket #54 has 0 elements.
bucket #55 has 0 elements.
bucket #56 has 1 elements.
bucket #57 has 0 elements.
bucket #58 has 0 elements.
bucket #59 has 1 elements.
bucket #60 has 1 elements.
bucket #61 has 1 elements.
bucket #62 has 2 elements.
bucket #63 has 1 elements.
bucket #64 has 0 elements.
bucket #65 has 0 elements.
bucket #66 has 1 elements.
bucket #67 has 1 elements.
bucket #68 has 0 elements.
bucket #69 has 0 elements.
bucket #70 has 0 elements.
bucket #71 has 1 elements.
bucket #72 has 0 elements.
bucket #73 has 0 elements.
bucket #74 has 0 elements.
bucket #75 has 1 elements.
bucket #76 has 1 elements.
bucket #77 has 0 elements.
bucket #78 has 2 elements.
bucket #79 has 2 elements.
bucket #80 has 0 elements.
bucket #81 has 0 elements.
bucket #82 has 0 elements.
bucket #83 has 0 elements.
bucket #84 has 0 elements.
bucket #85 has 0 elements.
bucket #86 has 1 elements.
bucket #87 has 0 elements.
bucket #88 has 1 elements.
bucket #89 has 0 elements.
bucket #90 has 1 elements.
bucket #91 has 1 elements.
bucket #92 has 0 elements.
bucket #93 has 0 elements.
bucket #94 has 0 elements.
bucket #95 has 0 elements.
bucket #96 has 0 elements.
bucket #97 has 0 elements.
bucket #98 has 0 elements.
bucket #99 has 1 elements.
bucket #100 has 1 elements.
bucket #101 has 0 elements.
bucket #102 has 0 elements.
bucket #103 has 1 elements.
bucket #104 has 0 elements.
bucket #105 has 1 elements.
bucket #106 has 0 elements.
bucket #107 has 0 elements.
bucket #108 has 0 elements.
bucket #109 has 1 elements.
bucket #110 has 2 elements.
bucket #111 has 1 elements.
bucket #112 has 1 elements.
bucket #113 has 1 elements.
bucket #114 has 0 elements.
bucket #115 has 0 elements.
bucket #116 has 0 elements.
bucket #117 has 1 elements.
bucket #118 has 0 elements.
bucket #119 has 0 elements.
bucket #120 has 0 elements.
bucket #121 has 0 elements.
bucket #122 has 0 elements.
bucket #123 has 0 elements.
bucket #124 has 0 elements.
bucket #125 has 0 elements.
bucket #126 has 2 elements.
bucket #127 has 0 elements.
bucket #128 has 3 elements.
bucket #129 has 2 elements.
bucket #130 has 0 elements.
bucket #131 has 0 elements.
bucket #132 has 1 elements.
bucket #133 has 1 elements.
bucket #134 has 1 elements.
bucket #135 has 0 elements.
bucket #136 has 1 elements.
bucket #137 has 0 elements.
bucket #138 has 0 elements.
bucket #139 has 0 elements.
bucket #140 has 1 elements.
bucket #141 has 0 elements.
bucket #142 has 1 elements.
bucket #143 has 1 elements.
bucket #144 has 1 elements.
bucket #145 has 1 elements.
bucket #146 has 1 elements.
bucket #147 has 0 elements.
bucket #148 has 1 elements.
bucket #149 has 1 elements.
bucket #150 has 0 elements.
bucket #151 has 0 elements.
bucket #152 has 1 elements.
bucket #153 has 1 elements.
bucket #154 has 1 elements.
bucket #155 has 0 elements.
bucket #156 has 0 elements.
bucket #157 has 2 elements.
bucket #158 has 0 elements.
bucket #159 has 0 elements.
bucket #160 has 2 elements.
bucket #161 has 0 elements.
bucket #162 has 2 elements.
bucket #163 has 0 elements.
bucket #164 has 0 elements.
bucket #165 has 0 elements.
bucket #166 has 1 elements.
bucket #167 has 1 elements.
bucket #168 has 1 elements.
bucket #169 has 0 elements.
bucket #170 has 1 elements.
bucket #171 has 0 elements.
bucket #172 has 0 elements.
bucket #173 has 1 elements.
bucket #174 has 0 elements.
bucket #175 has 0 elements.
bucket #176 has 1 elements.
bucket #177 has 0 elements.
bucket #178 has 0 elements.
bucket #179 has 1 elements.
bucket #180 has 0 elements.
bucket #181 has 0 elements.
bucket #182 has 0 elements.
bucket #183 has 0 elements.
bucket #184 has 1 elements.
bucket #185 has 0 elements.
bucket #186 has 0 elements.
bucket #187 has 1 elements.
bucket #188 has 0 elements.
bucket #189 has 0 elements.
bucket #190 has 0 elements.
bucket #191 has 1 elements.
bucket #192 has 1 elements.
bucket #193 has 0 elements.
bucket #194 has 2 elements.
bucket #195 has 0 elements.
bucket #196 has 0 elements.
bucket #197 has 0 elements.
bucket #198 has 2 elements.