Back to the Training Home
Back to the Training Home
Lesson: 38
Problem: 2782
Title: I am Lord Voldemort
Difficulty Level: 2.0
Date: MAR 03, 2009
Site: http://acm.tju.edu.cn/toj/showp2782.html
Given two strings, you have to print 'Yes' when frequencies of each letter of first string is equal to the frequencies of that
letter of the second string, otherwise print 'No'. Ignore case when comparing words.
Solution:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define maxn 100
int Fre1[maxn], Fre2[maxn];
char str1[maxn], str2[maxn];
int Cal() {
int i, k;
for(i = 0; i<26; i++) Fre1[i] = Fre2[i] = 0;
for(i = 0; str1[i]; i++) {
str1[i] = tolower(str1[i]);
k = str1[i] - 'a';
Fre1[k]++;
}
for(i = 0; str2[i]; i++) {
str2[i] = tolower(str2[i]);
k = str2[i] - 'a';
Fre2[k]++;
}
for(i = 0; i<26; i++) {
if(Fre1[i] != Fre2[i]) return 0;
}
return 1;
}
int main() {
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%s%s",str1,str2);
if(Cal()) {
printf("Yes\n");
}else {
printf("No\n");
}
}
return 0;
}
|