Anagram Check

Lab C Intermediate 20 points

Read two words and print YES if they are anagrams (ignoring case), using a letter-count array.

Input

Two words.

Output

YES or NO

Example

Input

Listen Silent

Output

YES
Sample input available Sample output available
Editor
C

Hints

Add 1 for each letter of the first word, subtract 1 for the second; all counts must end at 0.

Solution explanation

A 26-element count array compares letter multisets in linear time.

Show solution
#include <stdio.h>
#include <ctype.h>

int main() {
    char a[100], b[100];
    int count[26];
    for (int i = 0; i < 26; i++) count[i] = 0;
    scanf("%s %s", a, b);
    for (int i = 0; a[i] != '\0'; i++) count[tolower(a[i]) - 'a']++;
    for (int i = 0; b[i] != '\0'; i++) count[tolower(b[i]) - 'a']--;
    int ok = 1;
    for (int i = 0; i < 26; i++) {
        if (count[i] != 0) ok = 0;
    }
    printf(ok ? "YES\n" : "NO\n");
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD