Page 1 of 11

10252

Posted: Tue Mar 12, 2002 12:07 pm
by ahanys
It is easy to solve it:

Is my solution correct?
input:
aab
baa

output:
aab

or

input:
aab
baa

output:
ab

Do you know in which may be error?
Thanks

Code: Select all

/* @JUDGE_ID: 9072XC 10252 C++ */
#include <string.h>
#include <stdio.h>
	
int main() {

char a[10000],b[10000];

int prvkya[30];
int prvkyb[30];
int i=0;

while (gets(a) != NULL) {
	gets(b);
	if (strcmp(a, "") == 0) break;

	for (int k=0; k<26; k++) {
		prvkya[k] = 0;
		prvkyb[k] = 0;
	}

	for (i=0; i<strlen(a); i++) {
		prvkya[a[i]-'a']++;
	}
	for (i=0; i<strlen(b); i++) {
		prvkyb[b[i]-'a']++;
	}

	for (i=0; i<26; i++)	 {
		if ((prvkya[i]>0)&&(prvkyb[i]>0)) 
    for (int l=(prvkyb[i]>prvkya[i]?prvkya[i]:prvkyb[i]);
 l>0;
 l--)	{
        printf("%c",i+'a');
 }
	}
	printf("n");
}

return 0;
}
MAY ANYBODY TEST MY SOURCE AND TELL ME WHAT'S WRONG. THANKS
:smile:

<font size=-1>[ This Message was edited by: ahanys on 2002-03-19 12:17 ]</font>

Posted: Tue Mar 12, 2002 2:45 pm
by DemonCris
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??

Posted: Tue Mar 12, 2002 4:52 pm
by MegaS
Print 'a' min('a' in s1, 'a' in s2) times...
But there can be blank lines too (n)

Posted: Tue Mar 12, 2002 7:05 pm
by DemonCris
I strongly recommend using "gets" to read all the input.

Posted: Wed Mar 20, 2002 4:35 pm
by ante
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];
}

Posted: Thu Mar 21, 2002 3:08 am
by Stefan Pochmann
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...

Posted: Wed Mar 27, 2002 4:46 pm
by cyfra
Hi!

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 :sad:

I hope it will help :smile:

Good Luck !

Posted: Tue Apr 02, 2002 3:03 am
by ante
I solved it in C++ and still P.E.
Does anyone knows how to solve it without P.E

P.S:
Thanx Stefan for C++ tips.

Posted: Tue Apr 02, 2002 7:50 am
by Stefan Pochmann
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...

Posted: Tue Apr 02, 2002 10:17 pm
by ram
I got "WA" when I used "string". But got acc when i used char array. does any body know the reason??????

<font size=-1>[ This Message was edited by: ram on 2002-04-02 22:17 ]</font>

Posted: Wed Apr 03, 2002 4:11 am
by Stefan Pochmann
Highly depends on how you use them. I guess you used "cin >> s" and gets(...), repsectively?

Posted: Wed Apr 03, 2002 8:54 am
by ram
I used cin>>"string variable" and cin.getline("array variable",1003,'n')

But why should it make a difference??? Any idea???

<font size=-1>[ This Message was edited by: ram on 2002-04-03 08:54 ]</font>

Posted: Wed Apr 03, 2002 10:17 am
by Adrian Kuegel
It makes a difference, if there is a blank line. With cin.getline you read only the 'n', with cin>>string you get the next line.

Posted: Fri Apr 05, 2002 11:14 am
by ante
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

10252 - Common Permutation

Posted: Thu Dec 12, 2002 3:12 pm
by anupam
i don't know what the wrong case is.
i use LCS.
please check.
thanks.

:oops: :oops:
:oops: :oops:
#include<stdio.h>
#include<string.h>
#define N 1500

int p=0,c[N][N],f=0;
char b[N][N],x[N],y[N],a[N];

void print(int i,int j)
{
if(i==0 || j==0) return;
if(b[j]=='\\')
{
print(i-1,j-1);
/* printf("%c",x);*/
a[f++]=x;
p++;
}
else if(b[j]=='|')
print(i-1,j);
else print(i,j-1);
}

main()
{
int m,n,i,j,l;
int coun=0,q[27];
char temp;
while(1)
{
if(gets(x)==NULL) break;
gets(y);
m=strlen(x);
n=strlen(y);
for(i=m-1;i>=0;i--) x[i+1]=x;
for(i=n-1;i>=0;i--) y[i+1]=y;
x[m+1]=y[n+1]=0;
l=p=0;
for(i=1;i<=m;i++) c[0]=0,b[0]=' ';
for(i=0;i<=n;i++) c[0]=0;
b[0][0]=' ';
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(x==y[j])
{
c[i][j]=c[i-1][j-1]+1;
l++;
b[i][j]='\\';
}
else if(c[i-1][j]>=c[i][j-1])
{
c[i][j]=c[i-1][j];
b[i][j]='|';
}
else
{
c[i][j]=c[i][j-1];
b[i][j]='-';
}
f=0;
print(m,n);
a[f]=0;
for(i=0;i<26;i++) q[i]=0;
for(i=0;i<f;i++) q[a[i]-'a']++;
for(i=0;i<26;i++)
if(q[i])
printf("%c",i+'a');
printf("\n");
}
return 0;
}
[/b]