2007 Canadian Computing Competition, Stage 1

Problem J4: Anagram Checker

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

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

Output

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.

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 30, 2008

Problem Types: [Show]

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

I am just asking. When I do it at home, test cases 3 & 5 work, but when I do it on the judge, I get test cases 3 & 5 wrong. I wonder why?

Really? How did you get the test cases in the first place?
And I think it was the same problem I had before. For example, in GOOD and DOGS I think you're program deletes all the O's, instead of just 1 for 1, making it seem like an anagram. Check into that.

i donno..i am getting only half da mark...

Your code should work as i did multiple test cases. However, I did it a completely different way so WHEN you solve it you could check it out.
Sorry:)

i am getting a 60/70////.................i dont get whatzz wrong wid it...

Check your output format very carefully (punctuation?)

Whats wrong with the code that I submmitted?

It shouldn't give me a wrong error and it works fine on my computer. I also haven't used any reserved words as var names...(I think..)

You are forgetting that if string "s" has length "l", then the first character in s is actually s[0] and the last is s[l-1]: not s[1] and s[l]. Also, every time you perform an erase operation, the characters are shifted over, so the use of for loops is unnecessary.