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 100
- 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 countnumofAinstr(char s[],int n)
- {
- int result;
- char s1[MAX], s2[MAX];
- if(strlen(s) == 1)
- {
- puts(s);
- if(s[0]=='A')
- return 1;
- else
- return 0;
- }
- split(s,s1,s2);
- //result = countnumofAinstr(s1) + countnumofAinstr(s1);
- return countnumofAinstr(s1,n/2) + countnumofAinstr(s2,n/2);
- }
- int main(int argc, char const *argv[])
- {
- char s[] = "AAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAEEEEEAAAAAAAAAA";
- int l;
- l =strlen(s);
- printf("%d\n", countnumofAinstr(s,l));
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement