ANAGR - Anagrams
Two strings are said to be anagrams of each other if the letters of one string may be rearranged to make the other string. In this problem you’ll be given two strings. Your job is to find if the two strings are anagrams of each other. If they are not anagrams then find the lexicographically smallest palindrome (in lowercase letters) that may be appended to the end of one of the two strings so that they become anagrams of each other.
The lower and upper case letters are considered equivalent. The number of spaces or any other punctuation is not important.
Input
The first line of the input contains a number T, the number of test cases. T test cases follow. Each test case consists of two lines, one string in each line.
Output
For each test case output a single line. Print ‘YES’ (without the quotes) if the two strings are anagrams of each other. If they are not, then print the lexicographically smallest string as discussed above. If no such string exists, then print ‘NO LUCK’ (without the quotes).
Constraints
1<=T<=100
1<=length of the strings<=100
Sample
INPUT: 4 Computer programmer mature germ romp crop Awaaay away internet web the terminator I’m rotten hater OUTPUT: YES aa NO LUCK YES
hide comments
sumbayak_ae:
2016-04-16 10:36:02
what if the additional string is not pallindrome string? what should be added? |
|
devilcoder:
2015-11-23 10:03:57
http://www.spoj.com/submit/ANAGR/id=15688553
|
|
ronny_chan:
2015-08-27 02:39:47
Really I don't know what's wrong with this code.
|
|
Baojun Wang:
2014-09-15 07:43:33
Be ware of case when palindrome could be either:
|
|
simararorarox9:
2014-07-08 11:04:31
can anyone tell a corner case.. :\
|
|
dunnohyet:
2014-05-17 16:37:31
any corner cases |
|
Flago:
2014-04-24 14:20:20
Good one :D |
|
Jay H. Bosamiya:
2014-02-07 18:57:40
simple if you get it...
|
|
Anant Kumar:
2014-01-01 12:48:29
Good One! |
|
Sanjay Kumar:
2013-12-11 19:53:44
what if strings contains numbers |
Added by: | Abhinav92003 |
Date: | 2013-10-05 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |