413 - Up and Down Sequences

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

413 Up and Down Sequences

Post by C8H10N4O2 »

Can anyone help me figure out what is wrong with my code? It works for all the standard tests I can think of. ::This is a repost::
[cpp]#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;

const int UP=1;
const int DOWN=2;
const int UK=3;
int Trend,LastTrend,C,LD,LU,NU,ND;
vector<int> X;

double r(double v)
{
return double(int((v)*1000000+0.5))/1000000;
}

void FU()
{
LU+=C;
NU++;
}

void FD()
{
LD+=C;
ND++;
}

void main()
{
char B[1000],*P;
int i,N;

while(gets(B)!=NULL)
{
X.clear();
P=strtok(B," ");
while(P)
{
sscanf(P,"%d",&N);
X.push_back(N);
P=strtok(NULL," ");
}
X.pop_back();
if(X.size()>0)
{
Trend=UK;
LastTrend=UK;
C=0;
LU=0;
LD=0;
NU=0;
ND=0;
for(i=1;i<X.size();i++)
{
LastTrend=Trend;
if(X>X[i-1]) Trend=UP;
if(X<X[i-1]) Trend=DOWN;
if(Trend!=LastTrend)
{
if(LastTrend!=UK)
{
if(LastTrend==UP)
FU();
else
FD();
C=0;
}
}
C++;
}
if(Trend==UP) FU();
if(Trend==DOWN) FD();
if(NU==0)NU++;
if(ND==0)ND++;
printf("Nr values = %d: %.6f %.6fn",X.size(),r(double(LU)/NU),r(double(LD)/ND));
}
else
{
break;
}
}
}[/cpp]
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

I got your program Accepted. Don't use your r function, with %.6f the values are already rounded. And you should perhaps check your mailer settings, because the output line is very long.
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

Thanks a lot. I just found out that my ISP's mail server is horribly distorting my code. I am resubmitting a lot of stuff. It wasn't on my end:P
andrew10
New poster
Posts: 7
Joined: Wed Jan 08, 2003 10:18 am
Location: Indonesia

Re: 413 Up and Down Sequences

Post by andrew10 »

Can anyone help me figure out with C Language!!! Please!

Thank you
User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

please..please...help 413 ...

Post by ezra »

i frustrated for keep getting wa for p413. please someone kind help me and tell me what's the trouble of my code. :cry:

[c]
#include<stdio.h>
void main()
{
long seq[32];
int l,up,down,ctr,i,temp;
int nup[31],ndown[31];
int tup,tdown;
float avup,avdown;
void hup(int *ctr,int nup[],int *up,int *temp,long seq[]);
void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[]);
while(1)
{
scanf("%ld",&(seq[1]));
if(seq[1]==0)
break;
for(i=2;i<=30;i++)
{
scanf("%ld",&seq);
if(seq==0)
break;
}
l=i-1;
temp=0;
up=0;
down=0;
for(ctr=1;ctr<=l&&seq[ctr+1]!=0;)
{
if(seq[ctr]<seq[ctr+1]&&seq[ctr+1]!=0)
hup(&ctr,nup,&up,&temp,seq);
if(seq[ctr]==seq[ctr+1])
{
for(i=ctr;seq[ctr]==seq[ctr+1]&&seq[ctr+1]!=0;ctr++)
temp=temp+1;
}
if(seq[ctr]>seq[ctr+1]&&seq[ctr+1]!=0)
hdown(&ctr,ndown,&down,&temp,seq);
}
avup=0;
tup=0;
for(i=1;i<=up;i++)
tup=tup+nup;
if(up>0)
avup=(float)tup/(float)up;
avdown=0;
tdown=0;
for(i=1;i<=down;i++)
tdown=tdown+ndown;
if(down>0)
avdown=(float)tdown/(float)down;
printf("Nr values = %d: ",l);
printf("%f %f\n",avup,avdown);
}
}

void hup(int *ctr,int nup[],int *up,int *temp,long seq[])
{
*up=*up+1;
nup[*up]=*temp;
*temp=0;
for(;seq[*ctr]<=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]<seq[*ctr+1])
*temp=0;
nup[*up]=nup[*up]+1;
}
}

void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[])
{
*down=*down+1;
ndown[*down]=*temp;
*temp=0;
for(;seq[*ctr]>=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]>seq[*ctr+1])
*temp=0;
ndown[*down]=ndown[*down]+1;
}
}


[/c]
many thanks before. :wink:
User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

please..please...help 413 ...

Post by ezra »

i frustrated for keep getting wa for p413. please someone kind help me and tell me what's the trouble of my code. :cry:

[c]
#include<stdio.h>
void main()
{
long seq[32];
int l,up,down,ctr,i,temp;
int nup[31],ndown[31];
int tup,tdown;
float avup,avdown;
void hup(int *ctr,int nup[],int *up,int *temp,long seq[]);
void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[]);
while(1)
{
scanf("%ld",&(seq[1]));
if(seq[1]==0)
break;
for(i=2;i<=30;i++)
{
scanf("%ld",&seq);
if(seq==0)
break;
}
l=i-1;
temp=0;
up=0;
down=0;
for(ctr=1;ctr<=l&&seq[ctr+1]!=0;)
{
if(seq[ctr]<seq[ctr+1]&&seq[ctr+1]!=0)
hup(&ctr,nup,&up,&temp,seq);
if(seq[ctr]==seq[ctr+1])
{
for(i=ctr;seq[ctr]==seq[ctr+1]&&seq[ctr+1]!=0;ctr++)
temp=temp+1;
}
if(seq[ctr]>seq[ctr+1]&&seq[ctr+1]!=0)
hdown(&ctr,ndown,&down,&temp,seq);
}
avup=0;
tup=0;
for(i=1;i<=up;i++)
tup=tup+nup;
if(up>0)
avup=(float)tup/(float)up;
avdown=0;
tdown=0;
for(i=1;i<=down;i++)
tdown=tdown+ndown;
if(down>0)
avdown=(float)tdown/(float)down;
printf("Nr values = %d: ",l);
printf("%f %f\n",avup,avdown);
}
}

void hup(int *ctr,int nup[],int *up,int *temp,long seq[])
{
*up=*up+1;
nup[*up]=*temp;
*temp=0;
for(;seq[*ctr]<=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]<seq[*ctr+1])
*temp=0;
nup[*up]=nup[*up]+1;
}
}

void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[])
{
*down=*down+1;
ndown[*down]=*temp;
*temp=0;
for(;seq[*ctr]>=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]>seq[*ctr+1])
*temp=0;
ndown[*down]=ndown[*down]+1;
}
}


[/c]
many thanks before. :wink:
User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

please..please...help 413 ...

Post by ezra »

i frustrated for keep getting wa for p413. please someone kind help me and tell me what's the trouble of my code. :cry:

[c]
#include<stdio.h>
void main()
{
long seq[32];
int l,up,down,ctr,i,temp;
int nup[31],ndown[31];
int tup,tdown;
float avup,avdown;
void hup(int *ctr,int nup[],int *up,int *temp,long seq[]);
void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[]);
while(1)
{
scanf("%ld",&(seq[1]));
if(seq[1]==0)
break;
for(i=2;i<=30;i++)
{
scanf("%ld",&seq);
if(seq==0)
break;
}
l=i-1;
temp=0;
up=0;
down=0;
for(ctr=1;ctr<=l&&seq[ctr+1]!=0;)
{
if(seq[ctr]<seq[ctr+1]&&seq[ctr+1]!=0)
hup(&ctr,nup,&up,&temp,seq);
if(seq[ctr]==seq[ctr+1])
{
for(i=ctr;seq[ctr]==seq[ctr+1]&&seq[ctr+1]!=0;ctr++)
temp=temp+1;
}
if(seq[ctr]>seq[ctr+1]&&seq[ctr+1]!=0)
hdown(&ctr,ndown,&down,&temp,seq);
}
avup=0;
tup=0;
for(i=1;i<=up;i++)
tup=tup+nup;
if(up>0)
avup=(float)tup/(float)up;
avdown=0;
tdown=0;
for(i=1;i<=down;i++)
tdown=tdown+ndown;
if(down>0)
avdown=(float)tdown/(float)down;
printf("Nr values = %d: ",l);
printf("%f %f\n",avup,avdown);
}
}

void hup(int *ctr,int nup[],int *up,int *temp,long seq[])
{
*up=*up+1;
nup[*up]=*temp;
*temp=0;
for(;seq[*ctr]<=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]<seq[*ctr+1])
*temp=0;
nup[*up]=nup[*up]+1;
}
}

void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[])
{
*down=*down+1;
ndown[*down]=*temp;
*temp=0;
for(;seq[*ctr]>=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]>seq[*ctr+1])
*temp=0;
ndown[*down]=ndown[*down]+1;
}
}


[/c]
many thanks before. :wink:
User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

please...please...helppp..413

Post by ezra »

please someone kind to help me for i'm going frustrated to keep getting WA about this. please found the trouble of my code.
[c]
#include<stdio.h>
void main()
{
long seq[32];
int l,up,down,ctr,i,temp;
int nup[31],ndown[31];
int tup,tdown;
float avup,avdown;
void hup(int *ctr,int nup[],int *up,int *temp,long seq[]);
void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[]);
while(1)
{
scanf("%ld",&(seq[1]));
if(seq[1]==0)
break;
for(i=2;i<=30;i++)
{
scanf("%ld",&seq);
if(seq==0)
break;
}
l=i-1;
temp=0;
up=0;
down=0;
for(ctr=1;ctr<=l&&seq[ctr+1]!=0;)
{
if(seq[ctr]<seq[ctr+1]&&seq[ctr+1]!=0)
hup(&ctr,nup,&up,&temp,seq);
if(seq[ctr]==seq[ctr+1])
{
for(i=ctr;seq[ctr]==seq[ctr+1]&&seq[ctr+1]!=0;ctr++)
temp=temp+1;
}
if(seq[ctr]>seq[ctr+1]&&seq[ctr+1]!=0)
hdown(&ctr,ndown,&down,&temp,seq);
}
avup=0;
tup=0;
for(i=1;i<=up;i++)
tup=tup+nup;
if(up>0)
avup=(float)tup/(float)up;
avdown=0;
tdown=0;
for(i=1;i<=down;i++)
tdown=tdown+ndown;
if(down>0)
avdown=(float)tdown/(float)down;
printf("Nr values = %d: ",l);
printf("%f %f\n",avup,avdown);
}
}

void hup(int *ctr,int nup[],int *up,int *temp,long seq[])
{
*up=*up+1;
nup[*up]=*temp;
*temp=0;
for(;seq[*ctr]<=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]<seq[*ctr+1])
*temp=0;
nup[*up]=nup[*up]+1;
}
}

void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[])
{
*down=*down+1;
ndown[*down]=*temp;
*temp=0;
for(;seq[*ctr]>=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]>seq[*ctr+1])
*temp=0;
ndown[*down]=ndown[*down]+1;
}
}


[/c]
many thanks before..
User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

413 - Up and Down Sequences

Post by ezra »

i almost crazy for keep getting wa on this. :evil:
please be kind to tell me the bug of my code...please! :cry:
[c]
#include<stdio.h>
void main()
{
long seq[32];
int l,up,down,ctr,i,temp;
int nup[31],ndown[31];
int tup,tdown;
float avup,avdown;
void hup(int *ctr,int nup[],int *up,int *temp,long seq[]);
void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[]);
while(1)
{
scanf("%ld",&(seq[1]));
if(seq[1]==0)
break;
for(i=2;i<=30;i++)
{
scanf("%ld",&seq);
if(seq==0)
break;
}
l=i-1;
temp=0;
up=0;
down=0;
for(ctr=1;ctr<=l&&seq[ctr+1]!=0;)
{
if(seq[ctr]<seq[ctr+1]&&seq[ctr+1]!=0)
hup(&ctr,nup,&up,&temp,seq);
if(seq[ctr]==seq[ctr+1])
{
for(i=ctr;seq[ctr]==seq[ctr+1]&&seq[ctr+1]!=0;ctr++)
temp=temp+1;
}
if(seq[ctr]>seq[ctr+1]&&seq[ctr+1]!=0)
hdown(&ctr,ndown,&down,&temp,seq);
}
avup=0;
tup=0;
for(i=1;i<=up;i++)
tup=tup+nup;
if(up>0)
avup=(float)tup/(float)up;
avdown=0;
tdown=0;
for(i=1;i<=down;i++)
tdown=tdown+ndown;
if(down>0)
avdown=(float)tdown/(float)down;
printf("Nr values = %d: ",l);
printf("%f %f\n",avup,avdown);
}
}

void hup(int *ctr,int nup[],int *up,int *temp,long seq[])
{
*up=*up+1;
nup[*up]=*temp;
*temp=0;
for(;seq[*ctr]<=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]<seq[*ctr+1])
*temp=0;
nup[*up]=nup[*up]+1;
}
}

void hdown(int *ctr,int ndown[],int *down,int *temp,long seq[])
{
*down=*down+1;
ndown[*down]=*temp;
*temp=0;
for(;seq[*ctr]>=seq[*ctr+1]&&seq[*ctr+1]!=0;(*ctr)++)
{
if(seq[*ctr]==seq[*ctr+1])
*temp=*temp+1;
if(seq[*ctr]>seq[*ctr+1])
*temp=0;
ndown[*down]=ndown[*down]+1;
}
}


[/c]
thanks a million for helping..
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz »

your program didn't pass even sample input, have you noticed it?

this is your incorrect test case:
4 4 4 3 3 3 4 0
it should be
Nr values = 7: 1.000000 5.000000
but you have
Nr values = 7: 3.000000 5.000000

and here's more test cases for those who have difficulty solving it:

INPUT

Code: Select all

1 2 3 0
3 2 1 0
1 2 3 2 1 0
2 2 2 2 3 0
4 4 4 4 3 0
4 4 4 3 3 3 3 0
4 4 4 3 3 3 4 0
5 5 5 5 0
1 2 3 2 3 4 5 0
1 2 2 2 3 0
5 5 5 5 4 5 5 5 5 6 0
7 7 6 6 6 6 2 3 0
7 6 6 6 6 7 3 2 1 2 0
1 2 3 4 3 2 1 2 3 4 5 6 5 4 3 2 0
2 2 2 3 3 3 2 2 2 3 3 3 4 4 4 1 1 1 0
1 2 3 9 8 7 4 5 3 7 5 6 0
0
OUTPUT

Code: Select all

Nr values = 3:  2.000000 0.000000
Nr values = 3:  0.000000 2.000000
Nr values = 5:  2.000000 2.000000
Nr values = 5:  4.000000 0.000000
Nr values = 5:  0.000000 4.000000
Nr values = 7:  0.000000 6.000000
Nr values = 7:  1.000000 5.000000
Nr values = 4:  0.000000 0.000000
Nr values = 7:  2.500000 1.000000
Nr values = 5:  4.000000 0.000000
Nr values = 10:  5.000000 4.000000
Nr values = 8:  1.000000 6.000000
Nr values = 10:  1.000000 7.000000
Nr values = 16:  4.000000 3.500000
Nr values = 18:  5.500000 3.000000
Nr values = 12:  1.500000 1.666667
Hope it helps
keep it real!
nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

413 some more input/ output

Post by nymo »

i need some more sample input and output, can anyone post some? thanks in advance.
regards,
nymo
b
New poster
Posts: 2
Joined: Fri Sep 16, 2005 7:46 am

413 why wa

Post by b »

i don't understand why wa.plz help me.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max 100000

int main()
{
long a[max];
int i,j,l,m=0,check=0,check1=0,check2=0,k1check=0,k2check=0,in=0;
double totalup=0,totaldown=0,neutral=0,k1=1,k=1;

while(1)
{
scanf("%ld",&a[0]);
if(a[0]==0)
break;
for(l=1;;l++)
{
scanf("%ld",&a[l]);
//if(a[0]==0)
//goto M;
if(a[l]==0)
break;
}
totalup=0,totaldown=0,neutral=0,k=0,k1=0,k1check=0,k2check=0,in=0;
for(i=0;i<l-1;i++)
{
if(a<a[i+1])
{ if(in==0)
{
k++;
in=1;
}
check1=1;
totalup++;
k1check=1;
if(check==1)
{
if(k2check==1)
{
totaldown+=neutral;
k2check=0;
}
else
totalup=totalup+neutral;
check=0;
neutral=0;
//k++;
}
if(check2==1)
{
//totalup=totalup+neutral;
check2=0;
k++;
//m1=1;
}

}
else if(a>a[i+1])
{
if(in==0)
{
in=1;
k1++;
}

check2=1;
totaldown++;
k2check=1;
if(check==1)
{
if(k1check==1)
{
totalup=totalup+neutral;
k1check=0;
}
else
totaldown=totaldown+neutral;
check=0;
neutral=0;
k2check=1;
}
if(check1==1)
{
//totalup=totalup+neutral;
check1=0;
k1++;
}
/* if(m1==1)
{
m1=0;
k++; */
}
else if(a==a[i+1])
{
neutral++;
check=1;
}
}
if(check==1&&k1check==1)
{
totalup+=neutral;
k++;
check=0;
k1check=0;
}
if(check==1&&k2check==1)
{
totaldown+=neutral;
k1++;
check=0;k2check=0;
}
if(totaldown<=0)
{
if(k==0)
k=1;
printf("Nr values = %ld: %.6lf 0.000000\n",l,totalup/k);
}
else if(totalup<=0)
{
if(k1==0)
k1=1;
printf("Nr values = %ld: 0.000000 %.6lf\n",l,totaldown/k1);
}
else
{
if(k==0)
k=1;
if(k1==0)
k1=1;
printf("Nr values = %ld: %.6lf %.6lf\n",l,totalup/k,totaldown/k1);
}
m=0;
check=0,check1=0,check2=0;

}

}
}
Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

Try these cases :

INPUT :

Code: Select all

1 2 3 4 5 6 7 8 0
8 7 6 5 4 3 2 1 0
1 1 1 1 1 0
9 9  9 9 0
1 2 1 2 1 2 0
2 1 2 1 2 1 0
1 2 1 0
2 1 2 0
1 2 3 2 1 2 3 2 1 0
1 5 32 32 32 15 15 1 5 1 1 1 1 1 1 0
3 0
100 100 100 99 100 100 99 100 99 0
0 
OUTPUT :

Code: Select all

Nr values = 8:  7.000000 0.000000
Nr values = 8:  0.000000 7.000000
Nr values = 5:  0.000000 0.000000
Nr values = 4:  0.000000 0.000000
Nr values = 6:  1.000000 1.000000
Nr values = 6:  1.000000 1.000000
Nr values = 3:  1.000000 1.000000
Nr values = 3:  1.000000 1.000000
Nr values = 9:  2.000000 2.000000
Nr values = 15:  2.500000 4.500000
Nr values = 1:  0.000000 0.000000
Nr values = 9:  1.500000 1.666667
dmc
New poster
Posts: 5
Joined: Mon Dec 19, 2005 7:05 pm

Post by dmc »

jaracz wrote:your program didn't pass even sample input, have you noticed it?

this is your incorrect test case:
4 4 4 3 3 3 4 0
it should be
Nr values = 7: 1.000000 5.000000
but you have
Nr values = 7: 3.000000 5.000000

and here's more test cases for those who have difficulty solving it:

INPUT

Code: Select all

1 2 3 0
3 2 1 0
1 2 3 2 1 0
2 2 2 2 3 0
4 4 4 4 3 0
4 4 4 3 3 3 3 0
4 4 4 3 3 3 4 0
5 5 5 5 0
1 2 3 2 3 4 5 0
1 2 2 2 3 0
5 5 5 5 4 5 5 5 5 6 0
7 7 6 6 6 6 2 3 0
7 6 6 6 6 7 3 2 1 2 0
1 2 3 4 3 2 1 2 3 4 5 6 5 4 3 2 0
2 2 2 3 3 3 2 2 2 3 3 3 4 4 4 1 1 1 0
1 2 3 9 8 7 4 5 3 7 5 6 0
0
OUTPUT

Code: Select all

Nr values = 3:  2.000000 0.000000
Nr values = 3:  0.000000 2.000000
Nr values = 5:  2.000000 2.000000
Nr values = 5:  4.000000 0.000000
Nr values = 5:  0.000000 4.000000
Nr values = 7:  0.000000 6.000000
Nr values = 7:  1.000000 5.000000
Nr values = 4:  0.000000 0.000000
Nr values = 7:  2.500000 1.000000
Nr values = 5:  4.000000 0.000000
Nr values = 10:  5.000000 4.000000
Nr values = 8:  1.000000 6.000000
Nr values = 10:  1.000000 7.000000
Nr values = 16:  4.000000 3.500000
Nr values = 18:  5.500000 3.000000
Nr values = 12:  1.500000 1.666667
Hope it helps

7 6 6 6 6 7 3 2 1 2 0 -> Why is Nr values = 10: 1.000000 7.000000 ?

may be more correctly is 1.000000 3.500000 or not? please explain i have a problem with testing :o
xintactox
New poster
Posts: 14
Joined: Thu Dec 01, 2005 3:17 pm
Location: Brazil

413 - up and down sequences

Post by xintactox »

Hello everybody!

I tried lots of stuff but I think I didn't understand the problem at all... I think I am doing the wrong thing when the sequences has neutral values (no up nor down)...

It works fine for lots of inputs, but I tried with this

Code: Select all


1 2 3 4 5 6 7 8 0
8 7 6 5 4 3 2 1 0
1 1 1 1 1 0
9 9  9 9 0
1 2 1 2 1 2 0
2 1 2 1 2 1 0
1 2 1 0
2 1 2 0
1 2 3 2 1 2 3 2 1 0
1 5 32 32 32 15 15 1 5 1 1 1 1 1 1 0
3 0
100 100 100 99 100 100 99 100 99 0
0
and it fails on the 10th and in the last cases, but i just cant understand why!!!

itś giving me

Code: Select all


Nr values = 8:  7.000000 0.000000
Nr values = 8:  0.000000 7.000000
Nr values = 5:  0.000000 0.000000
Nr values = 4:  0.000000 0.000000
Nr values = 6:  1.000000 1.000000
Nr values = 6:  1.000000 1.000000
Nr values = 3:  1.000000 1.000000
Nr values = 3:  1.000000 1.000000
Nr values = 9:  2.000000 2.000000
Nr values = 15:  5.500000 3.000000
Nr values = 1:  0.000000 0.000000
Nr values = 9:  1.000000 6.000000
but according with a post about the same problem here in the forum it should be

Code: Select all


Nr values = 8:  7.000000 0.000000
Nr values = 8:  0.000000 7.000000
Nr values = 5:  0.000000 0.000000
Nr values = 4:  0.000000 0.000000
Nr values = 6:  1.000000 1.000000
Nr values = 6:  1.000000 1.000000
Nr values = 3:  1.000000 1.000000
Nr values = 3:  1.000000 1.000000
Nr values = 9:  2.000000 2.000000
Nr values = 15:  2.500000 4.500000
Nr values = 1:  0.000000 0.000000
Nr values = 9:  1.500000 1.666667
My code is as follows:

Code: Select all


#include <stdio.h>

#define UP 1
#define DOWN 2
#define NEUTRAL 3
int main()
{
   int serie[31];
   int NEUTRALVALUE;
   int totalUP;
   int totalDOWN;
   int totalUPSequences, totalDOWNSequences;
   int INDEX;   
   int stateOLD, stateNEW;
   int size;
   bool flag = true;
   int firstDeviation = -1;
   
   while(flag)
   {      
      totalUP = 0;
      totalDOWN = 0;
      NEUTRALVALUE = 0;
      totalUPSequences = 0;
      totalDOWNSequences = 0;   
      stateOLD = -1;   //indefinido      
            
      //lendo a s
Post Reply

Return to “Volume 4 (400-499)”