Can i ask for 7th test case of Char Swap... thats the only one that doesnt work???
Char swap 7th test case
If you paste your code we can help you :)
(Do you gente TLE or WA?)
(Do you gente TLE or WA?)
I get WA... :)
Me to, I don't know what am I doing wrong. Please look at my code and give me some hint. ;)
too*
I haven't seen your code, but the approach is quite straightforward:
Given a string s1 and s2:
For each letter i
s1[i] letter is hashed to s2[i]
Construct s3 using the hash, that is:
For each letter i
s3[i] = hash of letter s1[i]
Then check is s3 is equal to s2, if it's not equal then return false, else return true.
NOTE: You have to run this twice, the first run is s1, s2, and the next you have to swap their values.
Given a string s1 and s2:
For each letter i
s1[i] letter is hashed to s2[i]
Construct s3 using the hash, that is:
For each letter i
s3[i] = hash of letter s1[i]
Then check is s3 is equal to s2, if it's not equal then return false, else return true.
NOTE: You have to run this twice, the first run is s1, s2, and the next you have to swap their values.
My idea is to calculate number of repeating for each letter and have two arrays [1..26] Cnt1 and Cnt2. I sorted them and compare them. If they are identical then output "DA" ( Yes ) , else output "NE" ( No ) .
hahahah aleksandar we have the same idea :D LOL
And why that should work (Well, I see it doesn't, but give me a prof because I don't understand the idea behind your solution).
I assign number to each letter:
abbcdb
011231
and I do that for both strings:
abbcdb
011231
gttvet
011231
After that, I just compare these two arrays.
abbcdb
011231
and I do that for both strings:
abbcdb
011231
gttvet
011231
After that, I just compare these two arrays.
I don't know how to explain it, but it works ( just one case don't work ). It's similar with tgudlek's idea.
As I understand, you have not worried about positions of chars.
Try this case:
3
aab
bab
Try this case:
3
aab
bab
It prints 'DA'.
And it should print "NE", becouse word bab can not be made from aab.
it should print "NE".
:P
WTF, Ii must watch positions of chars in word?
I have done this task by a table of letters too. But instead of putting counts of letters, I've put which letter should be translated into other.
For example
char niz[26];
At the start it will have all values to 0, which means letters have no assigments yet. When i want to get letter into table, i have to check if letter in table is same as letter in word 2.
For example
char niz[26];
At the start it will have all values to 0, which means letters have no assigments yet. When i want to get letter into table, i have to check if letter in table is same as letter in word 2.
Ok, i'll try to do it the other way. ;)
And when I want to check if word 1 can be make by word 2, only thing I need is to count occurances of letter in niz. If same letter is more than once in niz, then word 1 can not be made from word 2.
Good luck! :)
Thanks ;)