| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Help RuntimeError#include <iostream.h>
#include <stdio.h>
const STACK_INIT_SIZE = 1005;
const STACKINCREMENT = 10;
typedef int SElemType;
typedef struct
{
SElemType * elem;
int top;
int stacksize;
int increment;
}SqStack;
void InitStack_Sq(SqStack &S,int maxsize = STACK_INIT_SIZE,int incresize = STACKINCREMENT)
{
S.elem = new SElemType[maxsize];
S.top = 0;
S.stacksize = maxsize;
S.increment = incresize;
}
void DestroyStack_Sq(SqStack &S)
{
delete [] S.elem;
S.top = 0;
S.stacksize = 0;
S.increment = 0;
}
void ClearStack_Sq(SqStack &S)
{
S.top = 0;
}
bool StackEmpty_Sq(SqStack S)
{
if(!S.top)
return true;
else
return false;
}
int StackLength_Sq(SqStack S)
{
return S.top;
}
void GetTop_Sq(SqStack S,SElemType &e)
{
e = S.elem[S.top - 1];
}
void Push_Sq(SqStack &S,SElemType e)
{
S.elem[S.top++] = e;
}
void Pop_Sq(SqStack &S,SElemType &e)
{
e = S.elem[--S.top];
}
void StackTraverse_Sq(SqStack S)
{
int i;
for(i = 0; i < S.top; i++)
{
cout << S.elem[i] <<endl;
}
}
int main()
{
int n;
SqStack S;
InitStack_Sq(S);
int *p;
int i, j, flag, k;
while(cin>>n && n){
ClearStack_Sq(S);
p = new int[n];
while(1){
flag = 1;
for(i = 0; i < n; i++){
cin>>p[i];
if(!p[0])
break;
}
if(!p[0])
break;
i = 1;
for(j = 0; j < n; j++){
if(!StackEmpty_Sq(S)){
GetTop_Sq(S, k);
if(p[j] < k){
flag = 0;
break;
}
else if(p[j] == k)
Pop_Sq(S,k);
}
if(p[j] > i )
for(i = i+1; i < p[j]; i++)
Push_Sq(S, i);
}
if(flag == 0)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
fflush(stdin);
}//while
printf("\n");
delete [] p;
}//while
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator