![:sad:](./images/smilies/icon_frown.gif)
484 - The Department of Redundancy Department
Moderator: Board moderators
Hi!
I havee the same problem....
This program is quite simple...
Program p484;
CONST
ma =100000;
VAR
tab:array[1..ma] of longint;
ile:array[1..ma] of longint;
q3,q1,x,n,pop,w,un:longint;
Function znajdz(zm1:longint):longint;
VAR
wyn,z1:longint;
begin
wyn:=0;
for z1:=1 to un do if tab[z1]=zm1 then wyn:=z1;
znajdz:=wyn;
end;
begin
read(n);
un:=1;
tab[un]:=n;
ile[un]:=1;
repeat
if eoln then readln;
read(n);
w:=znajdz(n);
if w<>0 then ile[w]:=ile[w]+1 else
begin
un:=un+1;
tab[un]:=n;
ile[un]:=1;
end;
until eof;
for x:=1 to un do
begin
Writeln(tab[x],' ',ile[x]);
end;
end.
I hope you will find my mistake ...
This program passed every test I made![:sad:](./images/smilies/icon_frown.gif)
I havee the same problem....
This program is quite simple...
Program p484;
CONST
ma =100000;
VAR
tab:array[1..ma] of longint;
ile:array[1..ma] of longint;
q3,q1,x,n,pop,w,un:longint;
Function znajdz(zm1:longint):longint;
VAR
wyn,z1:longint;
begin
wyn:=0;
for z1:=1 to un do if tab[z1]=zm1 then wyn:=z1;
znajdz:=wyn;
end;
begin
read(n);
un:=1;
tab[un]:=n;
ile[un]:=1;
repeat
if eoln then readln;
read(n);
w:=znajdz(n);
if w<>0 then ile[w]:=ile[w]+1 else
begin
un:=un+1;
tab[un]:=n;
ile[un]:=1;
end;
until eof;
for x:=1 to un do
begin
Writeln(tab[x],' ',ile[x]);
end;
end.
I hope you will find my mistake ...
This program passed every test I made
![:sad:](./images/smilies/icon_frown.gif)
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
One general advice: Use speaking variable names. You probably do that already, but I don't know the language you use. So they don't speak to me.
Arrays are not the problem. You (almost?) always have 32 MB you can use, so you're not even close to exceeding it. Of course I don't know anything about Pascal, maybe it behaves strangely with large arrays. In C/C++/Java I never had a problem.
And yes, it's one big sequence, exactly as stated in the input definition.
<font size=-1>[ This Message was edited by: Stefan Pochmann on 2002-03-28 02:00 ]</font>
Arrays are not the problem. You (almost?) always have 32 MB you can use, so you're not even close to exceeding it. Of course I don't know anything about Pascal, maybe it behaves strangely with large arrays. In C/C++/Java I never had a problem.
And yes, it's one big sequence, exactly as stated in the input definition.
<font size=-1>[ This Message was edited by: Stefan Pochmann on 2002-03-28 02:00 ]</font>
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
No, the input is correct (there are 3 "2" in the sequence.
I used an integer array with 1000000 elements, sorted it with an index array and stored the number of times of appearance in another array at position k, where k is the first appearence of this number in the sequence. Perhaps this helps you.
I used an integer array with 1000000 elements, sorted it with an index array and stored the number of times of appearance in another array at position k, where k is the first appearence of this number in the sequence. Perhaps this helps you.
I've made something like this:
var
liczba:array[-100000..100000] of integer;
q1,q2,q3,i,x:longint;
tab:array[0..1000000] of longint;
begin
repeat
read(x);
if liczba[x]=0 then
begin
tab[0]:=tab[0]+1;
tab[tab[0]]:=x;
end;
liczba[x]:=liczba[x]+1;
until eoln;
for i:=1 to tab[0] do
begin
writeln(tab,' ',liczba[tab]);
end;
end.
But I still have WA![:sad:](./images/smilies/icon_frown.gif)
var
liczba:array[-100000..100000] of integer;
q1,q2,q3,i,x:longint;
tab:array[0..1000000] of longint;
begin
repeat
read(x);
if liczba[x]=0 then
begin
tab[0]:=tab[0]+1;
tab[tab[0]]:=x;
end;
liczba[x]:=liczba[x]+1;
until eoln;
for i:=1 to tab[0] do
begin
writeln(tab,' ',liczba[tab]);
end;
end.
But I still have WA
![:sad:](./images/smilies/icon_frown.gif)
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
Read this line:
The input file will contain a sequence of integers (positive, negative, and/or zero).
That means the values are between -2^31 and 2^31-1. Therefore your program is not correct. I have described you my method. Try to implement it this way, or use an equivalent to map in C++ to store the values together with the number of apperances in the sequence.
The input file will contain a sequence of integers (positive, negative, and/or zero).
That means the values are between -2^31 and 2^31-1. Therefore your program is not correct. I have described you my method. Try to implement it this way, or use an equivalent to map in C++ to store the values together with the number of apperances in the sequence.
acm 484
why I get "Wrong Answer" ?
I change "char" to "int" but,"Wrong Answer"
Code: Select all
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
char y[1000000],*p;
long ane[100000],i,j,k,ans;
long temp[100000];
main()
{
while(gets(y))
{
for(i=0;i<100000;i++)
{temp[i]=0;ane[i]=0;}
i=0; ans=0;
p=strtok(y," ");
while(p!=NULL)
{
ane[i]=atoi(p);
p=strtok(NULL," \n");
i++;
}
for(j=0;j<i;j++){
if(temp[j]==1)
continue;
for(k=j;k<i;k++){
if(ane[j]==ane[k])
{
ans++;
temp[k]=1;
}
}
printf("%ld %ld\n",ane[j],ans);
ans=0;
}
}
}
Last edited by kelfin on Thu Nov 21, 2002 12:04 pm, edited 1 time in total.
...
The buffer size nop big enough?
-novice![:-?](./images/smilies/icon_confused.gif)
-novice
![:-?](./images/smilies/icon_confused.gif)
...
Change 'char' to 'int' and split the input as below,
[cpp]
while(gets(y))
{
int inp;
char *p = strtok(y);
while (p != NULL)
{ inp = atoi(p);
p = strtok(NULL," \n");
.....
.....
}
.....
.....
}
[/cpp]
-novice![:wink:](./images/smilies/icon_wink.gif)
[cpp]
while(gets(y))
{
int inp;
char *p = strtok(y);
while (p != NULL)
{ inp = atoi(p);
p = strtok(NULL," \n");
.....
.....
}
.....
.....
}
[/cpp]
-novice
![:wink:](./images/smilies/icon_wink.gif)