I have the same question ...
I sent these two version described above to online judge, but got WA.
The following is my method:
1. a table storing each character with the number of appearing in the two string individual.
2. if the character appears one or more times, then I determine how many the same character to print.
As described above in the second step, I altered a little and made another version.
But both got wrong ... >"< ...
Couldn't I misunderstand the meaning of the problem??
for i=1 to length(str1)
for j=1 to length(str2)
begin
if str1=str2[j] then
begin
delete char at j position in str2
add char at i position to temporary string
exit j loop
end
end
write alphabet. sorted temporary string
I got P.E. in Pascal, if anyone knows what's the catch ?
P.S: now I am trying to code it in C++, this is my sorting code and i don't know why I got SIGSEGV 11 error??? Please help !
unsigned int i,j;
char tmpStr[1000],ch[1];
for (i=0;i<strlen(tmpStr)-1;i++)
for(j=i+1;j<strlen(tmpStr);j++)
if (tmpStr>tmpStr[j])
{
ch[0] = tmpStr;
tmpStr=tmpStr[j];
tmpStr[j]=ch[0];
}
Maybe you should make the array bigger by one element to make room for the zero-char endmarker.
Btw, why don't you just use "sort( tmpStr, tmpStr+strlen(tmpStr) )"? Or at least swap(...)? In C++, these things are available...
I just made it in a simply way...
I have two tables from 1 to 255 each (they can be shorter)...
I read the letter and increse one call of the table -> inc(table[ord(char)])
then I do the same with the next line and put it into the second table...
Then
for x:=1 to 256 do
for y:=1 to min(tab[x],tab2[x]) do
Write(chr(x));
And that's all...
I think that they made something wrong with the task description
In the contest, everybody got a P.E. because they had no newline char at the end of the file. So try not putting a newline char after your last line.
During the contest, this was extremely annoying, since P.E.'s weren't accepted. They rejudged it afterwards, accepting P.E.'s, but of course lots of people had already wasted their time on it. Somebody had 35 submissions...
I give up from this problem and P.E. response, i tried many methods for output but none of them works,
if anyone has AC whthout P.E would you please send it to me at mailto: anblasko@globalnet.hr
Thanx in advance