## 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 upper case 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 Dec. 7, 2020, 1:45 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• 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 May 4, 2020, 5:52 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Feb. 25, 2021, 7:05 p.m.

The question specifies that there will only be uppercase letters.

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

why does my code not work? it should..?

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

try

LOTS
LOTT
• commented on Jan. 21, 2019, 6:25 p.m.

It shouldn't say prompt the users, since the inputs are supposed to be without any prompt. That line may be a bit misleading for beginners (and sometimes other people as well), and should therefore be removed.

• 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.