The same old problem.......WA
Can somebody help me?
Here is my code:
[c]
#include<stdio.h>
struct list{
int w;
int s;
int c;
};
void Longest_sequence(void);
void Qsort(int p, int r);
int Partition(int p, int r);
void display(int i);
int total,count;
int length[1100],predecessor[1100];
struct list ele[1100];
main()
{
long i,j,n,fl;
fl = 0;
count=0;
i=0;
while(1)
{
scanf("%d",&ele[i].w);
if(feof(stdin))
break;
scanf("%d",&ele[i].s);
length[i] = 1;
ele[i].c=i+1;
predecessor[i] = -1;
i++;
}
total = i;
Qsort(0,total-1);
Longest_sequence();
}
void Longest_sequence(void)
{
int i,j,x;
for (i=0; i<total-1;++i)
{
for (j=i+1;j<total;++j)
{
if (ele[j].w > ele[i].w)
{
if (length[i] + 1 > length[j])
{
length[j] = length[i] + 1;
x=j;
predecessor[j]=i;
}
}
}
}
printf("%d\n",length[x]);
display(x);
}
void Qsort(int p, int r)
{
long q;
if(p<r)
{
q = Partition(p,r);
Qsort(p,q);
Qsort(q+1,r);
}
}
int Partition(int p, int r)
{
struct list x,temp;
int i,j;
x = ele[p];
i = p-1;
j = r+1;
while(i<=j)
{
do {
--j;
}while(ele[j].s < x.s);
do {
++i;
}while(ele[i].s > x.s);
if(i<j)
{
temp = ele[i];
ele[i] = ele[j];
ele[j] = temp;
}
else
return j;
}
}
void display(int i)
{
if(predecessor[i]!=-1)
{
display(predecessor[i]);
}
printf("%d\n",ele[i].c);
}[/c]