Created
October 3, 2011 11:45
-
-
Save rkotov93/1258941 to your computer and use it in GitHub Desktop.
olymp2007_anagr
This file contains 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 <string.h> | |
#include <malloc.h> | |
int main() { | |
int* word; | |
int wordLen = -1; | |
int* anaWord; | |
int anaWordLen = -1; | |
int i, j = 0; | |
int n; | |
char c; | |
int count = 0; | |
freopen("input.txt", "r", stdin); | |
freopen("output.txt", "w", stdout); | |
word = (int*)malloc(100*sizeof(int)); | |
anaWord = (int*)malloc(100*sizeof(int)); | |
while (scanf("%c", &c) >= 'a') { | |
// | |
printf("%c", c); | |
// | |
word[c-97]++; | |
wordLen++; | |
} | |
// | |
printf("\n"); | |
// | |
scanf("%d", &n); | |
for (i = 0; i < n; i++) { | |
while (scanf("%c", &c) >= 'a') { | |
// | |
printf("%c", c); | |
// | |
anaWord[c-97]++; | |
anaWordLen++; | |
} | |
if (anaWordLen == wordLen) { | |
for (j = 0; j < wordLen; j++) | |
if (anaWord[j] != word[j]) { | |
// | |
printf("no"); | |
// | |
count--; | |
break; | |
} | |
count++; | |
} | |
} | |
printf("%d", count); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment