## CCC '07 J4 - Anagram Checker

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
##### Canadian Computing Competition: 2007 Stage 1, Junior #4

An anagram is a word or a phrase formed by rearranging the letters of another phrase such as ITEM and TIME. Anagrams may be several words long such as CS AT WATERLOO and COOL AS WET ART. Note that two phrases may be anagrams of each other even if each phrase has a different number of words (as in the previous example). Write a program to determine if two phrases are anagrams of each other.

#### Input Specification

The program should take two phrases, each on a separate line. You may assume that the input only contains uppercase letters and spaces.

#### Output Specification

The program will print out one of two statements: Is an anagram. or Is not an anagram.

#### Sample Input

CS AT WATERLOO
COOL AS WET ART

#### Sample Output

Is an anagram.

• commented on June 10, 2022, 2:37 p.m.

I keep on getting test case number 2 wrong but I don't know why...

• commented on Jan. 23, 2022, 1:02 p.m.

what am i doing wrong? it tells me i got it wrong on test case 7

• commented on Jan. 23, 2022, 2:07 p.m.

Try test case ABC and ABCD

Think it's because when a and b have different lense, list_a and list_b remain empty so str_a == str_b. in that case, anagram will be set to 0.

• commented on Oct. 28, 2020, 8:53 a.m.

If you're using C++ and you're stuck on test case #4, make sure to get the entire line and not just one word as input.

• commented on Dec. 17, 2019, 6:42 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Dec. 17, 2019, 8:16 p.m.

try

LOTS
LOTT
• commented on Nov. 27, 2018, 9:31 p.m.

I'm getting wrong at test case 6. What am I doing wrong?

• commented on Nov. 29, 2018, 8:16 p.m. edited

Your replace function is not working. A.replaceAll(" ", "") does not change the variable itself, you have to write A = A.replaceAll. When you initialize your character arrays, they are different lengths because there are different amounts of spaces.