Skip to content

Instantly share code, notes, and snippets.

@abatilo
Created January 18, 2016 05:32
Show Gist options
  • Save abatilo/8231f61efdc042b95aed to your computer and use it in GitHub Desktop.
Save abatilo/8231f61efdc042b95aed to your computer and use it in GitHub Desktop.
#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