提交时间:2026-05-15 15:41:35

运行 ID: 88786

#include <iostream> #include <string> using namespace std; int main() { int h, s; cin >> h >> s; string commands; cin >> commands; int depth = s; for (char cmd : commands) { if (cmd == 'u') { if (depth > 0) depth--; } else if (cmd == 'd') { if (depth < h) depth++; } } cout << depth << endl; return 0; }