关于本题我只想说。。。。审题!!! 题目要求输出Yes/No 我看成YES/NO 找了一上午看discuss才发现也有和我一样傻逼的人!! 要不是看了discuss, 估计会花我一天时间 T^T
还有就是,据学长的话说,尽量少用模板,我就下定决心,还是手写吧……
Memory | Time |
168K | 63MS |
#include <cstdio>
int main()
{
void push(int *stack, int *top, int n);
int pop(int *stack, int *top);
int n, num[1001], stack[1001];
while(scanf("%d", &n), n != 0)
{
int first, IsJudge;
while(scanf("%d", &first), first != 0)
{
IsJudge = 0;
num[0] = first;
int i, top = 0;
for(i = 1; i < n; i++)
{
scanf("%d", &num[i]);
}
int j = 1;
for(i = 0; i < n; i++)
{
for(; j <= num[i]; j++)
{
push(stack, &top, j);
}
if(num[i] == stack[top - 1])
{
pop(stack, &top);
continue;
}
if(num[i] < j)
{
if(stack[top - 1] != num[i])
{
printf("No\n");
IsJudge = 1;
break;
}
else
{
pop(stack, &top);
}
}
}
if(!IsJudge)
printf("Yes\n");
}
printf("\n");
}
return 0;
}
void push(int *stack, int *top, int n)
{
stack[*top] = n;
(*top)++;
}
int pop(int *stack, int *top)
{
(*top)--;
return stack[*top];
}