CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(Peer) » Anagram

Anagram

Problem code: TECH04

  • Submit
  • All Submissions

All submissions for this problem are available.

In this problem, you are given two strings S1 and S2, your task is to determine whether one string is an anagram of the other. An anagram of a string is a string obtained by permuting the letters of a string. For example aaba and aaab are anagrams, while abcd and deba are not.

Input

The first line would consist of the number of test cases 'T'. This would be followed by 'T' lines consisting of two space separated strings. The strings would consist of only letters 'a'-'z'. Each string would consist of no more than 20 characters.

Output

You have to print "YES" if one string is an anagram of the other or "NO" otherwise.

Example

Input:
2
aaba aaab
abcd deba

Output:
YES
NO

Author: technovanza10
Date Added: 12-01-2010
Time Limit: 2 sec
Source Limit: 50000 Bytes
Languages: C, C99 strict, CLOJ, CPP 4.0.0-8, CPP 4.3.2, F#, GO, JAVA, PERL6, PYTH 3.1.2, TEXT


  • Submit

Comments

  • Login or Register to post a comment.

There are some strings in the

xenon_15 @ 24 Apr 2010 12:36 PM

There are some strings in the input which are more than 20 characters. First, i tried with a char array of size 21, but i got a wrong answer and then i increased its size to get a correct answer.

Please correct the problem statement.

The length of the 2 input

urbaddy @ 26 Apr 2010 03:20 PM

The length of the 2 input strings may be different. be careful.

I agree with ashwani .. test

gunjanbansal @ 23 May 2010 10:57 PM

I agree with ashwani .. test cases are not correct ... some strings are more than 20 chars , my program dint worked when i tuk a string of 21 chars , but worked fine when it was increased to 100

I have been working on this

sends2aaron @ 6 Jul 2010 04:59 PM

I have been working on this and trying to find my mistake for days, and I just can't figure it out! I compare the total ASCII values for each string, I compare the length of each to make sure they are the same, and then lastly I do an element by element comparison of each individual character to make sure that THOSE match (since BB and AC can return an incorrect 'YES' when relying on ASCII total and length alone).

Stephen, I've read the FAQ. :)

Here is my most recent attempt: http://www.codechef.com/viewsolution/280869

I am new at this, and teaching myself. I apologize if I'm asking a question that you consider stupid.

@stephen sir please check my

anubhav.7nov @ 23 Jul 2010 11:14 AM

@stephen

sir please check my code http://www.codechef.com/viewsolution/290586

im getting wrong answer..

thank you

1 a aa

triplem @ 23 Jul 2010 12:41 PM

1

a aa

@stephen sir again please

anubhav.7nov @ 23 Jul 2010 09:29 PM

@stephen

sir again please check my code, its again giving wrong answer

http://www.codechef.com/viewsolution/290839

thank you

@Admin My program is showing

Maharshi Dutta @ 5 Aug 2010 12:39 PM

@Admin

My program is showing me errors.Please can you check the code???

Thanks in advance

http://www.codechef.com/viewsolution/299495

@Ashwani Sindhu,Gunjan : use

Fahim Dalvi @ 14 Aug 2010 05:18 PM

@Ashwani Sindhu,Gunjan : use string instead of char[] ;)

@Aaron Welch : I ran a check whether the strings were of same size, and got wrong answer. Removed that check and it worked fine :)

@admin .....wats wrong wid

sanchit.mittal @ 20 Aug 2010 01:13 AM

@admin .....wats wrong wid this solution......?

http://www.codechef.com/viewsolution/310143

Check your output for the

triplem @ 20 Aug 2010 09:59 AM

Check your output for the sample input. Carefully.

@stephen wats the prob

sanchit.mittal @ 20 Aug 2010 10:04 PM

@stephen wats the prob now.....wrong answer its givin.....

http://www.codechef.com/viewsolution/311003

i too was getting wrong

thechamp @ 31 Aug 2010 08:01 PM

i too was getting wrong answer even after utmost care. changed string size from 20 to 200, and was accepted :) try this

I don't think strings are

tijoforyou @ 1 Sep 2010 12:08 AM

I don't think strings are more than 20 characters. The problem clearly states, that " Each string would consist of no more than 20 characters". So max 20 characters. You need additional space for  terminating, character right? So, string size of 20 won't be sufficient. That doesn't mean strings have size more than 20. Obviously, Some strings have size 20.

:( internal error occurred in

noob_coder @ 11 Oct 2010 10:32 PM

:( internal error occurred in the system

@ admin I get the above error when I run my code What does it mean?

Also please have a look at http://www.codechef.com/viewsolution/356636

let me know whats wrong with it. it runs fine on my machine says wrong answer here ..


Dear admin , I tried my code

soorineeda @ 17 Jan 2011 08:59 AM

Dear admin ,

I tried my code on various inputs and it worked fine for the given inputs, but i am getting the wrong answer message. can i know for what input my code gives wrong answer?

http://www.codechef.com/viewsolution/425051

please help me in getting the problem with my code.

Thanks in advance.

accepted the code. ;) by

rahul_gupta5 @ 20 Jan 2011 11:09 PM

accepted the code. ;) by increasing the size of array from 20 to 25..

That's because you were only

triplem @ 21 Jan 2011 05:20 AM

That's because you were only considering the letters from A to T. Now you're only considering A to Y, and are lucky it was accepted.

@Rahul gupta Thanks i did

soorineeda @ 25 Jan 2011 06:37 PM

@Rahul gupta

Thanks i did same ...and my solution got accepted..

  @Stephen In the input it is

soorineeda @ 25 Jan 2011 06:39 PM

 

@Stephen

In the input it is mentioned max length of input string is 20 then why my code with array size 21 was not accepted..?

when i changed the size of array to 26 it got accepted...

This is a Peer problem,

triplem @ 26 Jan 2011 09:55 AM

This is a Peer problem, meaning it wasn't run by Codechef.. a large number of Peer problems have mistakes in the input/output/problem statement/etc sadly :(

pls tell me what is wrong in

abhinav8 @ 17 Feb 2011 03:28 AM

pls tell me what is wrong in this solution=>http://www.codechef.com/viewsolution/459506

pls tell me what is wrong in

abhinav8 @ 17 Feb 2011 03:29 AM

pls tell me what is wrong in this solution=>http://www.codechef.com/viewsolution/459506

@abhinav : if( ch1[j] !=

einstein010 @ 17 Feb 2011 07:00 AM

@abhinav : if( ch1[j] != ch2[j])

{

flag=0 // mistake here "flag=1" should be the statement here

break;

}

otherwise your program will never print NO if the strings are not of the same length

@abhishek thanks for

abhinav8 @ 17 Feb 2011 11:56 AM

@abhishek

thanks for reply

but,

my if statement is

 

  • if( flag )
  • {
  • cout<<"YES"<<endl;
  • }
  • else
  • {
  • cout<<"NO"<<endl;
  • /
  • }
  • if i make flag=1,it will execute if part(i.e. print yes),but in this i have to print no ,that's why flag=0 is given there.
  • thanks again for reply

    Try the sample input with the

    triplem @ 17 Feb 2011 12:13 PM

    Try the sample input with the test cases the other way around.

    @admin Please check this

    desire @ 17 Feb 2011 12:13 PM

    @admin Please check this solution http://www.codechef.com/viewsolution/459617

    What is wrong in this..Thanks in Advance

    test cases should be changed

    piyushurpade @ 28 Mar 2011 12:13 AM

    test cases should be changed because of SIZE

    i got AC for 50 len. but WR for 21

    @admin can u plz inform me

    jravi96 @ 16 Apr 2011 02:31 PM

    @admin can u plz inform me what kind of compile error is this in java--

     

    /sources/Main.java:8: error while writing javaapplication2.Main: /tmp/javaapplication2/Main.class (Permission denied) public class Main ^ 1 error

    hi all...I dint understand

    hungrycoder @ 17 Jun 2011 06:34 PM
    hi all...I dint understand what is the problem with my code.....its fine with all the test cases I enter...pls help me out somebody http://www.codechef.com/viewsolution/575843

    @stephen please help me.....

    hungrycoder @ 17 Jun 2011 06:41 PM
    @stephen please help me.....

    @hungrycoder try: 1 aaa

    balajiganapath @ 17 Jun 2011 08:44 PM
    @hungrycoder try: 1 aaa aaa answer should be YES

    @balajiganapath ya its YES ma

    hungrycoder @ 17 Jun 2011 09:19 PM
    @balajiganapath ya its YES ma code showing......dunno why its wrong????

    @hungrycoder try: 1 abb abc

    balajiganapath @ 17 Jun 2011 09:24 PM
    @hungrycoder try: 1 abb abc answer should be NO

    @balajiganapath ....thank

    hungrycoder @ 17 Jun 2011 09:28 PM
    @balajiganapath ....thank u...i understand....now lemme try....anyways thanks a lot...u r very much helpful....

    @balajiganapath i rectified

    hungrycoder @ 17 Jun 2011 09:44 PM
    @balajiganapath i rectified that but still showing wrong answer....what the hell is this??whatever I submit its showing wrong....sry to disturb u....bt please rectify my fault

    http://www.codechef.com/views

    hungrycoder @ 17 Jun 2011 09:46 PM
    http://www.codechef.com/viewsolution/575941 is the link to my latest effort

    sry link shud be

    hungrycoder @ 17 Jun 2011 10:01 PM
    sry link shud be http://www.codechef.com/viewsolution/575951

    #include #include

    suresh316 @ 26 Jun 2011 12:11 PM
    #include #include int main() { char s1[25],s2[25]; double str1=0,str2=0; int i,t,m=0,res[10]; cin>>t; while(m>s1; cin>>s2; for(i=0,str1=0;i

    can anybody tell me why it

    suresh316 @ 27 Jun 2011 12:05 AM
    can anybody tell me why it shows wrong answer for my program. http://www.codechef.com/viewsolution/583939

    I think many of us are having

    rajdeep345 @ 29 Jul 2011 12:11 AM
    I think many of us are having problems with this particular program. Even I am getting wrong answer on this site though it is giving me correct answer on my machine. I request the admin to kindly check the code below: http://www.codechef.com/viewsolution/608838

    hi....i m getting wrong

    anu120987 @ 3 Sep 2011 10:51 PM
    hi....i m getting wrong answer even after checking for many cases....can anyone plz check my code. .http://www.codechef.com/viewsolution/645289 thanx in advance

    Will the Two Strings have

    prattsishunk @ 30 Oct 2011 02:40 AM
    Will the Two Strings have different Length???

    No, they should have the same

    k1ps @ 9 Nov 2011 04:27 PM
    No, they should have the same length.

    if array size 21 wrong

    cs1rangers @ 7 Feb 2012 03:03 AM
    if array size 21 wrong answer!!!!...if 26 correct :)

    @admin: Please correct the

    vrushank @ 22 Feb 2012 01:33 PM
    @admin: Please correct the problem statement. There are some strings with more than 20 characters. Cost me 3 submissions :(

    Can any body tell me what is

    goodcode @ 12 Apr 2012 11:51 PM
    Can any body tell me what is wrong with my code? http://www.codechef.com/viewsolution/978082

    @goodcode- increase ur string

    shashank_jain @ 13 Apr 2012 08:17 PM
    @goodcode- increase ur string size to 30.. some string in input file are more than 20.

    @problemsetter- common man!!.

    shashank_jain @ 13 Apr 2012 08:18 PM
    @problemsetter- common man!!. how can two anagrams are of unequal length after all they are just permutation of each other !!! :)

    @Shashank_jain- Still

    goodcode @ 13 Apr 2012 11:23 PM
    @Shashank_jain- Still worng!!!!!

    @goodcode- see this

    shashank_jain @ 14 Apr 2012 01:18 PM
    @goodcode- see this http://www.codechef.com/viewsolution/978584 may be this can help you !!! :)

    @admin there may be some test

    akshaybansal20 @ 6 May 2012 04:26 PM
    @admin there may be some test cases where the length of string is larger than 20

    SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

    Programming Competition Fetching successful submissions
    Directi Go for Gold

    HELP

    Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

     

    • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
    • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
    • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
    • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
    • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
    • If you are still having problems, see a sample solution here.

    CodeChef is a global programming communityCodeChef hosts online programming competitions
    CodeChef is a non-commercial competitive programming community
    • About CodeChef
    • About Directi
    • CEO's Corner
    • C-Programming
    • Programming Languages
    • Contact Us
    © 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
    In order to report copyright violations of any kind, send in an email to copyright@codechef.com
    CodeChef a product of Directi
    The time now is:
    CodeChef - A Platform for Aspiring Programmers

    CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

    Practice Section - A Place to hone your 'Computer Programming Skills'

    Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

    Compete - Monthly Programming Contests and Cook-offs

    Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

    Discuss

    Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

    CodeChef Community

    As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

    Go For Gold

    The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

    Domain Name Registration, Web hosting, and Website Design provided by BigRock.com