Thread: Hashing In C
View Single Post
Old Jan 9th, 2008, 5:51 PM   #9
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Re: Hashing In C

Quickly done STL version (using your input loop) - untested - you probably would need to fix up the includes
c++ Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <map>
  5.  
  6. int main() {
  7. unsigned n, x, size, mode=0;
  8.  
  9. freopen("mode.in", "rt", stdin);
  10. scanf("%d\n", &n);
  11.  
  12. std::map<int,int> counts;
  13. while (n--) {
  14. scanf("%d\n", &x);
  15. if (( size = ++counts[x]) )> mode) mode = size;
  16. }
  17. printf("%d\n", mode);
  18.  
  19. return 0;
  20. }
The Dark is offline   Reply With Quote