Advertisement
bkit4s0

[hash 'a' str] error

Dec 31st, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #icclude<stdio.h>
  2. #include<string.h>
  3. void split(char *s, char *s1, char *s2)
  4. {
  5.     int l, m;
  6.     l = strlen(s);
  7.     m = l/2;
  8.     for (int i = 0; i < m; ++i)
  9.     {
  10.         s1[i] = s[i];
  11.         s2[i] = s[l - m + i];
  12.     }
  13. }
  14. int numofA(char *s)
  15. {
  16.     int count;
  17.     count = 0;
  18.     for (int i = 0; i < strlen(s); ++i)
  19.     {
  20.         if(s[i] == 'A')
  21.             count++;
  22.     }
  23.     return count;
  24. }
  25. int max(int x, int y)
  26. {
  27.     int result;
  28.     if(x > y)
  29.         result = x;
  30.     else
  31.         result = y;
  32.     return result;
  33. }
  34. int hash(char *s)
  35. {
  36.     int result;
  37.     char *s1, *s2;
  38.     result = numofA(s);
  39.     if(strlen(s) > 1)
  40.     {
  41.         split(s,s1,s2);
  42.         result += max(hash(s1),hash(s1));
  43.     }
  44.     return result;
  45. }
  46. int main(int argc, char const *argv[])
  47. {
  48.     char *s = "AEEAEEAAE";
  49.     printf("%d\n", hash(s));
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement