Created
January 18, 2016 05:32
-
-
Save abatilo/8231f61efdc042b95aed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
int main() { | |
const char *A = "powerful"; | |
const int sizeA = 8; | |
const char *B = "fulewopr"; | |
const int sizeB = 8; | |
int lettersA[26]; | |
int lettersB[26]; | |
for (int i = 0; i < 26; ++i) { | |
lettersA[i] = 0; | |
lettersB[i] = 0; | |
} | |
bool permutation = true; | |
if (sizeA != sizeB) { | |
permutation = false; | |
} | |
else { | |
for (int i = 0; i < sizeA; ++i) { | |
++lettersA[A[i] - 'a']; | |
++lettersB[B[i] - 'a']; | |
} | |
for (int i = 0; i < 26; ++i) { | |
if (lettersA[i] != lettersB[i]) permutation = false; | |
} | |
} | |
printf("%s\n", permutation ? "Strings are permutations" : "Strings are not permutations"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment