484 - The Department of Redundancy Department
Moderator: Board moderators
Because scanf stops input after getting space, here you can take input by scanf and sore it in an array. u should take input as a string and then by searching the array give the output
here is my code:
[cpp]
#include<stdio.h>
#include<string.h>
struct d
{
char a[100];
long num;
}data[100];
long nc;
long check(char n[])
{
long i;
for(i=0;i<nc;i++)
if(!strcmp(data.a,n))
return i;
strcpy(data.a,n);
nc++;
return i;
}
void main()
{
long b,i;
char n[100];
nc=0;
//freopen("484.in","r",stdin);
while(scanf("%s",n)==1)
{
b=check(n);
data.num++;
}
for(i=0;i<nc;i++)
{
printf("%s %ld\n",data.a,data.num);
}
}
[/cpp]
here is my code:
[cpp]
#include<stdio.h>
#include<string.h>
struct d
{
char a[100];
long num;
}data[100];
long nc;
long check(char n[])
{
long i;
for(i=0;i<nc;i++)
if(!strcmp(data.a,n))
return i;
strcpy(data.a,n);
nc++;
return i;
}
void main()
{
long b,i;
char n[100];
nc=0;
//freopen("484.in","r",stdin);
while(scanf("%s",n)==1)
{
b=check(n);
data.num++;
}
for(i=0;i<nc;i++)
{
printf("%s %ld\n",data.a,data.num);
}
}
[/cpp]
484 - The Department of Redundancy Department
I have wrong answer.Who can help me?
Code: Select all
#include<stdio.h>
#include<iostream.h>
main()
{
int i=0,j=0,n=0,i1=0,j1=0,count[100],i3=0,k=0,i4=0,k1=0;
char in[1000],save[100][1000];
for(i=0;i<=100;i++)
count[i]=0;
gets(in);
n=strlen(in);
for(i=0;i<=n;i++)
{
if(in[i]!=' '&&in[i]!='\0'&&in[i]>='0'&&in[i]<='9'||in[i]=='-')
{
if(in[i]=='-')
k1++;
if(k1==1&&in[i+1]>='0'&&in[i+1]<='9')
{
save[i1][j1]=in[i];
j1++;
}
}
else
{
for(i3=0;i3<i1;i3++)
{
if(strcmp(save[i3],save[i1])==0)
{
count[i3]++;
k++;
for(i4=0;i4<=j1;i4++)
save[i1][i4]=0;
j1=0;
}
}
if(k==0)
{
count[i1]++;
i1++;
j1=0;
}
k=0;
k1=0;
}
}
for(j=0;j<i1;j++)
if(save[j][0]!=' '&&save[j][0]!='\0')
cout << save[j] <<" "<<count[j]<<endl ;
}
Re: ...
I change , but "Wrong Answer".Fresh wrote: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
The code in up.
to rakeb:
I test and submit your source code, but judge send me "Runtime Error (SIGSEGV)". Therefore, I think you can check your code again. Maybe you could tell me whether it can run correctly.
I got AC,and I offer some information about this problem:
1.the integer number(positive/negative/zero) is ranged from 65535
to -65536,so you can use scanf("%d",&XXX);
2.The amout of all integers is below 10000.
Good luck!
I test and submit your source code, but judge send me "Runtime Error (SIGSEGV)". Therefore, I think you can check your code again. Maybe you could tell me whether it can run correctly.

I got AC,and I offer some information about this problem:
1.the integer number(positive/negative/zero) is ranged from 65535
to -65536,so you can use scanf("%d",&XXX);
2.The amout of all integers is below 10000.
Good luck!
Hello, I try to solve this problem but get WA.
If the input is ranged from 65535 to -65536 and is below 10000, it should work.
Can anyone have any opinion?
If the input is ranged from 65535 to -65536 and is below 10000, it should work.
Can anyone have any opinion?
Last edited by Eric on Sat Jan 31, 2004 6:35 am, edited 2 times in total.
I wonder if there are trailing spaces in the input......
What can I do if so?? (I'm using Pascal......)
I couldn't find any mistakes in my code. My algorithm is:
1. Input number
2. If first occurence then
...2.1 increment n
...2.2 and store the number in an array
...2.3 set occurence = 1
3. else
...3.1 increment occurence
4. Back to step 1
5. Output
What should I do??? Please help!!!!!!
What can I do if so?? (I'm using Pascal......)
I couldn't find any mistakes in my code. My algorithm is:
1. Input number
2. If first occurence then
...2.1 increment n
...2.2 and store the number in an array
...2.3 set occurence = 1
3. else
...3.1 increment occurence
4. Back to step 1
5. Output
What should I do??? Please help!!!!!!
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Special input routine?little joey wrote: I had to write my own input routine before I could get AC in Pascal...
Can you give me some hint??? I really want to know...... Plz......
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
Read the input line by line into a string, and extract the numbers from this string by processing the line.
It's a bit of a spoiler, but consider this little program[pascal]{$MODE DELPHI}
program test;
function line2nums(var line:ansistring;var num:array of integer):integer;
var
i,j,len:integer;
begin
result:=0;
len:=length(line);
i:=1;
while (i<=len) do begin
while ((i<=len) and not (line in ['-','0'..'9'])) do inc(i);
j:=i;
while ((i<=len) and (line in ['-','0'..'9'])) do inc(i);
if (i>j) then begin
val(copy(line,j,i-j),num[result]);
inc(result);
end;
end;
end;
var
num:array[1..1000] of integer;
line:ansistring;
nums,i:integer;
begin
line:=' -9 3 22222 9847 rubbish -123456 more rubbish 777 ';
nums:=line2nums(line,num);
for i:=1 to nums do writeln(num);
end.[/pascal]
It compiles using FPC, the same compiler the judge uses, but certainly not with BP (I don't know about Delphi). No comments, you should be able to figure out what it does. Use ansistring, string is to short for this particular input. The val() procedure makes it a little slow, so write your own if you want more speed. The function can't cope with monsters like ('123-456'), but I don't think they are there.
good luck.
It's a bit of a spoiler, but consider this little program[pascal]{$MODE DELPHI}
program test;
function line2nums(var line:ansistring;var num:array of integer):integer;
var
i,j,len:integer;
begin
result:=0;
len:=length(line);
i:=1;
while (i<=len) do begin
while ((i<=len) and not (line in ['-','0'..'9'])) do inc(i);
j:=i;
while ((i<=len) and (line in ['-','0'..'9'])) do inc(i);
if (i>j) then begin
val(copy(line,j,i-j),num[result]);
inc(result);
end;
end;
end;
var
num:array[1..1000] of integer;
line:ansistring;
nums,i:integer;
begin
line:=' -9 3 22222 9847 rubbish -123456 more rubbish 777 ';
nums:=line2nums(line,num);
for i:=1 to nums do writeln(num);
end.[/pascal]
It compiles using FPC, the same compiler the judge uses, but certainly not with BP (I don't know about Delphi). No comments, you should be able to figure out what it does. Use ansistring, string is to short for this particular input. The val() procedure makes it a little slow, so write your own if you want more speed. The function can't cope with monsters like ('123-456'), but I don't think they are there.
good luck.
Thanks, little joey!!!! Finally I got an AC!!!!!!!!
Remainder for Pascal users:
There ARE trailing spaces, and the input comes in more than ONE line......
No. of numbers in the input < 8000
Remainder for Pascal users:
There ARE trailing spaces, and the input comes in more than ONE line......
No. of numbers in the input < 8000

7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
484,cant understand the input format
i am having trouble with the prob 484 . i cant take the input of the prob. as it is a multiple input prob so the output for differnet input block should be different (with a new line).but my programs gives the output together .
tha means the complete out put together. here is my code , and sorry for my not so good english;
pliz tell me if there are any efficient algorithm. is my process right??
thanx in advance
Riyad
/* start of code*/
/*----------------*/
#include<stdio.h>
#define size 10000
struct num{
long int n;
int fr;
};
struct num obj[size];
int index;
long int input[size];
int iindex;
void init(){
register int i;
index=iindex=0;
for(i=0;i<size;i++){
obj.fr=0;
}
}
int search(int x)
{
register int i;
for(i=0;i<index;i++){
if(obj.n==x){
return i;
}
}
return -1;
}
void calculate(){
register int i,check ;
for(i=0;i<iindex;i++){
if(i==0){
obj[index].n=input;
obj[index].fr=1;
index++;
}
else{
check=search(input);
if(check!=-1){
obj[check].fr++;
}
else if(check==-1){
obj[index].n=input;
obj[index].fr=1;
index++;
}
}
}
}
void print(){
register int i;
for(i=0;i<(index-1);i++){
printf("%ld %d\n",obj.n,obj.fr);
}
}
int main(){
//freopen("input.in","rt",stdin);
register int cinput;
scanf("%d",&cinput);
while(cinput>0){
init();
while(scanf("%ld",&input[iindex++])!=EOF){
;
}
calculate();
print();
printf("\n");
cinput--;
}
return 0;
}
/*----------------*/
/*end of code */
tha means the complete out put together. here is my code , and sorry for my not so good english;
pliz tell me if there are any efficient algorithm. is my process right??
thanx in advance
Riyad



/* start of code*/
/*----------------*/
#include<stdio.h>
#define size 10000
struct num{
long int n;
int fr;
};
struct num obj[size];
int index;
long int input[size];
int iindex;
void init(){
register int i;
index=iindex=0;
for(i=0;i<size;i++){
obj.fr=0;
}
}
int search(int x)
{
register int i;
for(i=0;i<index;i++){
if(obj.n==x){
return i;
}
}
return -1;
}
void calculate(){
register int i,check ;
for(i=0;i<iindex;i++){
if(i==0){
obj[index].n=input;
obj[index].fr=1;
index++;
}
else{
check=search(input);
if(check!=-1){
obj[check].fr++;
}
else if(check==-1){
obj[index].n=input;
obj[index].fr=1;
index++;
}
}
}
}
void print(){
register int i;
for(i=0;i<(index-1);i++){
printf("%ld %d\n",obj.n,obj.fr);
}
}
int main(){
//freopen("input.in","rt",stdin);
register int cinput;
scanf("%d",&cinput);
while(cinput>0){
init();
while(scanf("%ld",&input[iindex++])!=EOF){
;
}
calculate();
print();
printf("\n");
cinput--;
}
return 0;
}
/*----------------*/
/*end of code */
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
thanx a lot
thanx buddy i got it ac now . i some how made a stupid mistake
by considering 484 as a multiple input problem . problems like this can be made by we new people. thanx once agian for u r help.
bye
Riyad


bye
Riyad

HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN