C++代码求调(测试样例能过但提交WA了)
查看原帖
C++代码求调(测试样例能过但提交WA了)
738885
Scholar618楼主2022/7/31 15:44
#include <iostream>
using namespace std;
int stack[1000020], top;

int main() {
	int T;
	string str;
	cin >> T;
	for (int i = 0; i < T; i++) {
		int n;
		unsigned long long int x;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> str;
			if (str == "push") {
				cin >> x;
				stack[top++] = x;
			}
			else if (str == "query") {
				if (top == 0) {
					cout << "Anguei!" << endl;
				}
				else {
					cout << stack[top - 1] << endl;
				}
			}
			else if (str == "size") {
				cout << top << endl;
			}
			else if (str == "pop") {
				if (top > 0) {
					top--;
				}
				else {
					cout << "Empty" << endl;
				}
			}
		}
		top = 0;
	}
   return 0;
}
2022/7/31 15:44
加载中...