top1编程
← 返回题目
题解

【基础】水下探测器

1 条题解

  • 0
    @ 2026-7-29 0:17:42
    #include<bits/stdc++.h>
    using namespace std;
    int h,s;
    string a;
    int main(){
    	cin>>h>>s>>a;
    	for(int i=0;i<a.size();i++){
    		if(a[i]=='u') s=max(0,s-1);
    		if(a[i]=='d') s=min(h,s+1);
    	}
    	cout<<s;
    	return 0;
    }
    
    • 1