Posted: Wed Jun 08, 2005 4:18 am
thanks
finally got ac
finally got ac
Code: Select all
#include<iostream>
using namespace std;
int main(void)
{
int N,i,stack[1001],permutation[1001],top,per,j;
while(cin>>N&&N)
{
while(cin>>permutation[1])
{
if(permutation[1]!=0)
{
for(i=2;i<=N;i++)
cin>>permutation[i];
top = 0;
per = 1;
for(i=1;i<=N;i++)
{
if(permutation[per]==i)
{
per++;
while(permutation[per]==stack[top])
{
top--;
per++;
}
}
else
{
top++;
stack[top] = i;
}
}
if(top==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
{
cout<<endl;
break;
}
}
}
return 0;
}
Code: Select all
#include<stdio.h>
void push(int);
int pop(void);
int stack[1001]={0},top=0;
void main()
{
int noc=0;
for(;;)
{
scanf("%d",&noc);
if(noc==0)
break;
for(;;)
{
int rail[1001]={0},i,flag=0,j,diff=0,large=0,k=1,p;
scanf("%d",&rail[1]);
if(rail[1]==0)
break;
for(i=2;i<=noc;i++)
scanf("%d",&rail[i]);
for(j=0;j<noc;j++)
{
if(rail[j]<rail[j+1])
{
diff=rail[j+1]-large;
for(p=1;p<diff;p++)
push(large+(k++));
large=rail[j+1];
k=1;
}
else if(rail[j]>rail[j+1])
{
if(rail[j+1]!=pop())
{
flag=1;
break;
}
}
}
if(!flag)
printf("Yes\n");
else if(flag==1)
printf("No\n");
}
printf("\n");
}
}
void push(int data)
{
stack[++top]=data;
}
int pop()
{
int temp;
temp=stack[top];
top--;
return temp;
}
Code: Select all
String solve(Vector cur, Vector des) {
Vector st = new Vector();
Vector b = new Vector();
for (int i = 0; i < des.size(); i++) {
Integer next = (Integer) des.elementAt(i);
int idx = cur.indexOf(next);
if (idx >= 0) {
while (idx > 0) {
Integer w = (Integer) cur.elementAt(0);
cur.removeElementAt(0);
st.addElement(w);
idx--;
}
cur.removeElementAt(0);
b.addElement(next);
} else {
Integer w = (Integer) st.elementAt(st.size() - 1);
if (w.equals(next)) {
st.removeElementAt(st.size() - 1);
b.addElement(next);
} else {
return "No";
}
}
}
if (cur.size() > 0 || st.size() > 0)
return "No";
return "Yes";
}
Code: Select all
Code: Select all
Yes
No
<===blank line
Yes
<===blank line
<=== cursor is here
Yea, it worked, thank you very much.Debashis Maitra wrote:for your input my output isthis may help uCode: Select all
Yes No <===blank line Yes <===blank line <=== cursor is here
best of luck
Code: Select all
Removing the code .. as it was giving AC
But you are printing a blank line between cases. Print a blank line after each case.there is one empty line after the lines corresponding to one block of the input file
Code: Select all
5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
5 6 4 3 2 1
1 2 3 4 5 6
0
10
1 2 3 4 5 10 9 8 7 6
0
0
Code: Select all
Yes
No
Yes
Yes
Yes
Yes
Code: Select all
Yes^
No^
^
Yes^
Yes^
Yes^
^
Yes^
^