WA 231 Testing the catcher

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

Moderator: Board moderators

gettin wa plz some one help

Postby Sadasidha08 » Fri Jun 18, 2010 8:24 pm

#include<iostream.h>
#include<stdlib.h>

#define MAX 100000

void swap(long& x,long& y)
{
int t=x;
x=y;
y=t;
}
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}

long arry[MAX][MAX]={0,};
int main()
{
long ar1[MAX],ar2[MAX];

long n,t=0,i,j,k;

while(1)
{
t++;
cin>>n;
if(n==-1)
break;
j=0;
while(1)
{
ar2[j]=ar1[j]=n;
for(k=j;k>0;k--)
{
if(ar2[k]>ar2[k-1])
swap(ar2[k],ar2[k-1]);
}
cin>>n;
j++;
if(n==-1)
break;


}


int m=j;

for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
if(ar1[i-1]==ar2[j-1])
arry[i][j]=arry[i-1][j-1]+1;
else
arry[i][j]=max(arry[i][j-1],arry[i-1][j]);
}
}


if(t!=1)
cout<<"\n";

cout<<"Test #"<<t<<":\n";
cout<<" maximum possible interceptions: "<<arry[m][m];

}


return 0;
}
Sadasidha08
New poster
 
Posts: 3
Joined: Mon Apr 05, 2010 8:09 pm

Previous

Return to Volume II

Who is online

Users browsing this forum: No registered users and 1 guest