【DidaOJ】[283]Stack? Queue?

Problem Description

Loading...

Problem Analysis

This tests your understanding of stacks and queues
But you don’t need to use them directly
You only need to make a judgment

Because the problem says it’s either a queue or a stack
Because if it’s a queue, the elements must correspond one-to-one
So you can check whether they are equal one by one
Otherwise it’s a stack

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
int main() {
	int n;
	int a[12],b[12];
	while(scanf("%d",&n)!=EOF) {
		for(int i=0; i<n; i++)
			scanf("%d",&a[i]);
		for(int i=0; i<n; i++)
			scanf("%d",&b[i]);
		int i;
		for(i=0; i<n; i++)
			if(a[i]!=b[i])
				break;
		if(i<n)
			printf("1\n");
		else
			printf("0\n");
	}
	return 0;
}

Problem link: 【DidaOJ】[283]Stack ? Queue ?

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...