I tried to compile and run your code on my computer using VC++, but it crashed. Something wrong with your code or is it my computer ? Anyways, here are some test cases
the quick brown fox jumped over the lazy dog.
the lazy brown dog jumped over the quick fox. ;)
thE quicK browN foX jumpeD oveR thE lazY doG.
the quick brown of R jumped ovex THE lazy do G :(
[O ] <- this is our national flag. I love BANGLADESH
bangladesh is our motherland. we love her. this is our flag -> [O ]
[O ]**[O ] xyz (1+2)^3=9 xyz xyz xyz xxx yyy zzz ppp ppp qqq
Well... my program ran only the first and second cases correctly... The case 3 is a little confusing...
The letter 'Y' maps to 'A' and I don't know why. Look at my table for case 3:
Frequencies in KNOWN text:
a = 1
b = 1
c = 1
d = 2
e = 4
f = 1
g = 1
h = 2
i = 1
j = 1
k = 1
l = 1
m = 1
n = 1
o = 4
p = 1
q = 1
r = 2
t = 2
u = 2
v = 1
w = 1
x = 1
y = 1
z = 1
Frequencies in ENCODED text:
a = 3
b = 1
c = 1
d = 1
e = 1
i = 1
n = 1
y = 1
(ordering them... I've got:)
KNOWN sorted:
4 = e
4 = o
2 = t
2 = h
2 = u
2 = r
2 = d
1 = q
1 = i
1 = c
1 = k
1 = b
1 = w
1 = n
1 = f
1 = x
1 = j
1 = m
1 = p
1 = v
1 = l
1 = a
1 = z
1 = y
1 = g
ENCODED sorted:
3 = a
1 = b
1 = c
1 = n
1 = y
1 = i
1 = d
1 = e
Making the mapping:
e <=> a
o <=> b
t <=> c
h <=> n
u <=> y
r <=> i
d <=> d
q <=> e
A mapped the most frequently letters each other as the problem said.
But I think that the problem is my ordering algorithm.
What is this algorithm idea? I really don't know
I thought that only character in ENCODED text could map to character in KNOWN text.. but it doesn't happen in case 4.
The leter 'K' in "quick" maps to 'D' in which doesn't exist in KNOWN text:
"123abbccc654987the remaining letters are gone :O"
Could you help me? I'm getting crazy...
Thanks in advance!
If two chars have different frequency
then they are ordered accordig to the frequencly.
else ( they have same frequency )
they are ordered lexicographically
To arrange according to frequency, the char with higher frequency comes before the char with lower frequency. For example, if 'x' appears 3 times and 'k' appears 2 times, then 'x' comes before 'k'.
I used the ASCII values of the chars to do the lexicographic ordering. For example, if 'a' and 'b' has same frequency, then 'a' comes before 'b'. i.e. the char with smaller ASCII value comes first.
Are you sure this case is wrong ? This output is generated by my accepted code. I assumed that if a char does not appear then its frequency is zero. So i order and then map the chars with zero frequency too, did not ignore them. But i think, the judge input has all the chars of English alphabet at least once in the first part. So it does not make any difference if you assume this or not.
So the KNOWN text contain no blank lines? The FIRST blank line separate the KNOWN and ENCODE text? In the spec. it only said they are separated by a blank line, but does not speciaify which blank line.
I know this thread has been closed for a while. I tried solving this problem, and it seems ridiculously easy. I tried all the sample input provided, and they all worked. When I submit, I get TLE. I don't know why it should do that though. I sort an array of size 26 using bubble sort. That shouldn't cause it to TLE. And I have no other big time loops anywhere else. Does anyone see why I get TLE?
code cut after accepted. Main speedup:
change sytem.out.print to system.out.write
change Character.tolower/toupper to c +- 32
use arrays instead of vectors.
bubble sort ok for this problem
thanks Darko!
Last edited by jjtse on Sat Oct 07, 2006 3:42 am, edited 1 time in total.
I am not sure what Character.toLower() does, but I think (char)(c+32) would be faster.
Oh, and going the other way - Character.toUpper() is (char)(c-32).
And you want to use System.out.write() instead of print().
And Vector is slow, too.
When you fix those, and if it's still TLE I'll take another look.
[EDIT] I don't think any of the above is the reason - I just tried it and it keeps looping for the second string for some reason (like it never reads null). Now I'm puzzled, too