这字符串使用的问题在哪?找不着
查看原帖
这字符串使用的问题在哪?找不着
1020171
Jason0802楼主2024/4/2 21:26
#include <cstdio>
int a[10005];
int head=1,tail=1;
void push(int x){
	head++;
	a[head+1]=x;
}
void pop(){
	if (tail==head) printf("ERR_CANNOT_POP");
	else tail--;
}
int query(){
	if (head>tail) return a[head];
	return 0;
}
int size(){
	return head-tail;
}
int main(){
	int n;
	scanf("%d",&n);
	char op;
	for (int i=1;i<=n;i++){
		scanf("%s",op);
		printf("%d ",n);
		if (op=='1'){
			int x;
			scanf("%d",&x);
			push(x);
		}
		if (op=='2'){
			pop();
		}
		if (op=='3'){
			if (query()!=0) printf("%d\n",query());
			else printf("ERR_CANNOT_QUERY");
		}
		if (op=='4'){
			printf("%d\n",size());
		}
	}
	return 0;
}

是“scanf("%s",op);”有问题吗?

2024/4/2 21:26
加载中...