Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. char word[50], maxword[50], wword[50];
  6. int n, i, j, maxcount, count, equals;
  7. char **words;
  8.  
  9. scanf("%d", &n);
  10. words = malloc(n*sizeof(char*));
  11. for ( i = 0; i < n; i++ )
  12. {
  13. words[i] = malloc(50*sizeof(char));
  14. }
  15.  
  16. for (i = 0; i < n; i++) {
  17. scanf("%s", word);
  18. for (j = 0; j < 50; j++) {
  19. words[i][j] = word[j];
  20. }
  21. }
  22.  
  23. maxcount = 0;
  24. for (i = 0; i < n; i++) {
  25. for (j = 0; j < 50; j++) {
  26. word[j] = words[i][j];
  27. }
  28. count = 0;
  29. for (i = 0; i < n; i++) {
  30. equals = 1;
  31. for (j = 0; j < 50; j++) {
  32. if (word[j] != words[i][j]) {
  33. equals = 0;
  34. }
  35. }
  36. if (equals == 1) {
  37. count++;
  38. }
  39. }
  40. if (count > maxcount) {
  41. maxcount = count;
  42. for (j = 0; j < 50; j++) {
  43. maxword[j] = word[j];
  44. }
  45. }
  46. }
  47.  
  48. printf("%s %d\n", maxword, count);
  49.  
  50. return(0);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement