Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #define MAX 10
- void split(char s[], char s1[], char s2[])
- {
- int l, m;
- int i,j;
- l = strlen(s);
- m = l/2;
- for (i = 0; i < m; ++i)
- {
- s1[i] = s[i];
- //s2[i] = s[l - m + i]; // can't use to split s2
- }
- s1[i] = '\0';
- for (i = m; i < l; ++i)
- {
- s2[i-m] = s[i];
- }
- s2[i-m] = '\0';
- }
- int numofA(char s[])
- {
- int count;
- count = 0;
- for (int i = 0; i < strlen(s); ++i)
- {
- if(s[i] == 'A')
- count++;
- }
- return count;
- }
- int max(int x, int y)
- {
- int result;
- if(x > y)
- result = x;
- else
- result = y;
- return result;
- }
- int hash(char s[])
- {
- int result;
- char s1[MAX], s2[MAX];
- result = numofA(s);
- if(strlen(s) > 1)
- {
- split(s,s1,s2);
- result += max(hash(s1),hash(s2));
- }
- return result;
- }
- int main(int argc, char const *argv[])
- {
- char s[] = "AEAAAE";
- //int l;
- //l =strlen(s);
- printf("%d\n", hash(s));
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement