- 袁野老师 的博客
2026北京普及强化Day4比赛Code
- @ 2026-2-11 14:59:34
A
#include<bits/stdc++.h>
using namespace std;
int n,top,x;
string opt;
int st[100010];
int main(){
cin >> n;
while (n--) {
cin >> opt;
if (opt == "push") {
cin >> x;
st[++top] = x;
} else if (opt == "pop") {
if (top)
top--;
else cout << "Empty\n";
} else if (opt == "top") {
if (top)
cout << st[top] << "\n";
else cout << "Empty\n";
} else if (opt == "isEmpty") {
if (top == 0) cout << "Yes\n";
else cout << "No\n";
} else if (opt == "size") {
cout << top << "\n";
}
}
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
int n,top,x;
string opt;
int st[100010];
int main(){
cin >> n;
while (n--) {
cin >> opt;
if (opt == "A") {
cin >> x;
st[++top] = x;
} else if (opt == "U") {
top--;
} else if (opt == "F") {
st[top-1] += st[top];
top--;
} else if (opt == "R") {
swap(st[top], st[top-1]);
}
}
for (int i=1; i<=top; ++i) cout << st[i] << " ";
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
bool check(string s) {
int top = 0;
for (auto c:s) {
if (c == '(') top++;
else {
if (top == 0) return false;
else top--;
}
}
return top == 0;
}
int main(){
cin >> n;
for (int i=1; i<=n; ++i) {
cin >> s;
if (check(s)) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
D
#include<bits/stdc++.h>
using namespace std;
string s;
char st[100010];
int top;
int main(){
cin >> s;
for (auto c:s) {
if (c == 's') {
if (top && st[top] == 's') top--, c = 'S';
else st[++top] = 's';
}
if (c == 'S') {
if (top && st[top] == 'S') top--;
else st[++top] = 'S';
}
// for (int i=1; i<=top; ++i) cout << st[i];
// cout << "\n";
}
for (int i=1; i<=top; ++i) cout << st[i];
return 0;
}
E
#include<bits/stdc++.h>
using namespace std;
int T;
int n;
int ok[2010],t[10010],a[2010];
int main(){
cin >> T;
while (T--) {
cin >> n;
memset(ok, 0, sizeof(ok));
memset(t, 0, sizeof(t));
for (int i=1; i<=n; ++i) cin >> a[i];
for (int i=n; i>=1; --i) {
if (t[a[i]]) continue;
else t[a[i]] = 1,cout << a[i] << " ";
}
cout << "\n";
}
return 0;
}
F
#include<bits/stdc++.h>
using namespace std;
int n,q,top,stx[2000010],sty[2000010],opt,p;
string d;
int main(){
cin >> n >> q;
for (int i=n; i>=1; --i) stx[++top] = i, sty[top] = 0;
while (q--) {
cin >> opt;
if (opt == 1) {
cin >> d;
int nx = stx[top], ny = sty[top];
if (d == "R") nx++;
else if (d == "L") nx--;
else if (d == "U") ny++;
else ny--;
stx[++top] = nx, sty[top] = ny;
} else {
cin >> p;
cout << stx[top+1-p] << " " << sty[top+1-p] << "\n";
}
}
return 0;
}