## CCC '07 J4 - Anagram Checker

View as PDF

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### 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 May 4, 2020, 5:52 p.m.

make sure to convert to lowercase

• 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 Sept. 6, 2019, 6:22 p.m.

NOOO! Forgot the dot.

• 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 Jan. 3, 2019, 8:05 p.m. edited

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

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