CCC '07 J4 - Anagram Checker

View as PDF

Submit solution

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


Sample Output

Is an anagram.


  • -7
    Dav_Did  commented on Dec. 7, 2020, 1:45 p.m.

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

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

  • -5
    Orion222  commented on May 4, 2020, 5:52 p.m.

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

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

      The question specifies that there will only be uppercase letters.

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

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

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

  • 1
    jfu0952  commented on Nov. 27, 2018, 9:31 p.m.

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

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