All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
-
ahanys
- New poster
- Posts: 24
- Joined: Mon Nov 19, 2001 2:00 am
- Location: N/A
-
Contact:
Post
by ahanys » Tue Mar 12, 2002 12:07 pm
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
<font size=-1>[ This Message was edited by: ahanys on 2002-03-19 12:17 ]</font>
-
DemonCris
- New poster
- Posts: 25
- Joined: Sun Feb 24, 2002 2:00 am
- Location: Taiwan
Post
by DemonCris » Tue Mar 12, 2002 2:45 pm
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??
-
MegaS
- New poster
- Posts: 9
- Joined: Tue Feb 05, 2002 2:00 am
Post
by MegaS » Tue Mar 12, 2002 4:52 pm
Print 'a' min('a' in s1, 'a' in s2) times...
But there can be blank lines too (n)
-
DemonCris
- New poster
- Posts: 25
- Joined: Sun Feb 24, 2002 2:00 am
- Location: Taiwan
Post
by DemonCris » Tue Mar 12, 2002 7:05 pm
I strongly recommend using "gets" to read all the input.
-
ante
- New poster
- Posts: 8
- Joined: Wed Mar 20, 2002 2:00 am
Post
by ante » Wed Mar 20, 2002 4:35 pm
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];
}
-
Stefan Pochmann
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
-
Contact:
Post
by Stefan Pochmann » Thu Mar 21, 2002 3:08 am
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...
-
cyfra
- Experienced poster
- Posts: 144
- Joined: Thu Nov 22, 2001 2:00 am
- Location: Gdynia, Poland
Post
by cyfra » Wed Mar 27, 2002 4:46 pm
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
I hope it will help
Good Luck !
-
ante
- New poster
- Posts: 8
- Joined: Wed Mar 20, 2002 2:00 am
Post
by ante » Tue Apr 02, 2002 3:03 am
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.
-
Stefan Pochmann
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
-
Contact:
Post
by Stefan Pochmann » Tue Apr 02, 2002 7:50 am
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...
-
ram
- New poster
- Posts: 30
- Joined: Wed Mar 06, 2002 2:00 am
-
Contact:
Post
by ram » Tue Apr 02, 2002 10:17 pm
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>
-
Stefan Pochmann
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
-
Contact:
Post
by Stefan Pochmann » Wed Apr 03, 2002 4:11 am
Highly depends on how you use them. I guess you used "cin >> s" and gets(...), repsectively?
-
ram
- New poster
- Posts: 30
- Joined: Wed Mar 06, 2002 2:00 am
-
Contact:
Post
by ram » Wed Apr 03, 2002 8:54 am
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>
-
Adrian Kuegel
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
Post
by Adrian Kuegel » Wed Apr 03, 2002 10:17 am
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.
-
ante
- New poster
- Posts: 8
- Joined: Wed Mar 20, 2002 2:00 am
Post
by ante » Fri Apr 05, 2002 11:14 am
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
-
anupam
- A great helper
- Posts: 405
- Joined: Wed Aug 28, 2002 6:45 pm
-
Contact:
Post
by anupam » Thu Dec 12, 2002 3:12 pm
i don't know what the wrong case is.
i use LCS.
please check.
thanks.
#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]
"Everything should be made simple, but not always simpler"