Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- void print_arr(int *arr, int n)
- {
- printf("\n");
- printf("[");
- for(int i = 0; i < n-1; i++)
- {
- printf("%d, ", arr[i]);
- }
- printf("%d]", arr[n-1]);
- printf("\n\n");
- }
- int small_in_big(char *s1, char *s2) // s1 = small, s2 = big
- {
- // small = jim
- // big = mojair
- int new_small[26] = {};
- int new_big[26] = {};
- int len_small = strlen(s1);
- int len_big = strlen(s2);
- for(int i = 0; i < len_small; i++)
- new_small[s1[i] - 97]++; // j = 106, index = 106-97 = 9
- for(int j = 0; j < len_big; j++)
- new_big[s2[j] - 97]++; // m = 109, index = 109-97 = 12
- for(int k = 0; k < len_small; k++)
- {
- if(new_big[s1[k] - 97]) // new_big[9]
- new_big[s1[k] - 97]--;
- else
- return 0;
- }
- return 1;
- }
- void main()
- {
- char str1[] = "mim";
- char str2[] = "mojair";
- int result = small_in_big(str1, str2);
- printf("%d", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement