提交时间:2024-02-29 16:57:49

运行 ID: 42491

#include<bits/stdc++.h> using namespace std; int main() { int h, s; string str; cin >> h >> s >> str; for (int i = 0; str[i] != '\0'; i++) { if(str[i] == 'u' && s > 0) { s = s - 1; }else if(str[i] == 'd' && s < h) { s = s + 1; } } cout << s; return 0; }