AnagramProblem code: TECH04 |
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 |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions

There are some strings in the
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
The length of the 2 input strings may be different. be careful.
I agree with ashwani .. test
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
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
@stephen
sir please check my code http://www.codechef.com/viewsolution/290586
im getting wrong answer..
thank you
1 a aa
1
a aa
@stephen sir again please
@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
@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
@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
@admin .....wats wrong wid this solution......?
http://www.codechef.com/viewsolution/310143
Check your output for the
Check your output for the sample input. Carefully.
@stephen wats the prob
@stephen wats the prob now.....wrong answer its givin.....
http://www.codechef.com/viewsolution/311003
i too was getting wrong
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
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
:( 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
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
accepted the code. ;) by increasing the size of array from 20 to 25..
That's because you were only
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
@Rahul gupta
Thanks i did same ...and my solution got accepted..
@Stephen In the input it is
@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,
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
pls tell me what is wrong in this solution=>http://www.codechef.com/viewsolution/459506
pls tell me what is wrong in
pls tell me what is wrong in this solution=>http://www.codechef.com/viewsolution/459506
@abhinav : if( ch1[j] !=
@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
@abhishek
thanks for reply
but,
my if statement is
thanks again for reply
Try the sample input with the
Try the sample input with the test cases the other way around.
@admin Please check this
@admin Please check this solution http://www.codechef.com/viewsolution/459617
What is wrong in this..Thanks in Advance
test cases should be changed
test cases should be changed because of SIZE
i got AC for 50 len. but WR for 21
@admin can u plz inform me
@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
@stephen please help me.....
@hungrycoder try: 1 aaa
@balajiganapath ya its YES ma
@hungrycoder try: 1 abb abc
@balajiganapath ....thank
@balajiganapath i rectified
http://www.codechef.com/views
sry link shud be
#include #include
can anybody tell me why it
I think many of us are having
hi....i m getting wrong
Will the Two Strings have
No, they should have the same
if array size 21 wrong
@admin: Please correct the
Can any body tell me what is
@goodcode- increase ur string
@problemsetter- common man!!.
@Shashank_jain- Still
@goodcode- see this
@admin there may be some test