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.
Comments
I keep on getting test case number 2 wrong but I don't know why...
what am i doing wrong? it tells me i got it wrong on test case 7
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.
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.
This comment is hidden due to too much negative feedback. Show it anyway.
try
I'm getting wrong at test case 6. What am I doing wrong?
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.