1 solutions
-
0
C++ :
#include <iostream> using namespace std; int main(){ int h,s; string str; cin>>h>>s>>str; for(int i=0;i<str.size();i++){ if(str[i]=='u'){ if(s>0){ s--; } }else{ if(s<h){ s++; } } } cout<<s; }
Java :
import java.util.Scanner; public class Main { public static void main(String[]args) { Scanner scan=new Scanner(System.in); int h=scan.nextInt();//在湖底时到水面的距离 int s=scan.nextInt();//最初水下深度 String str=scan.next();//指令 scan.close(); for(int i=0;i<str.length();i++) { char ch=str.charAt(i); if(ch=='u') {//上浮 if(s>0) s-=1; } else if(ch=='d') {//下沉 if(s<h) s+=1; } } System.out.println(s); } }
Python :
n=list(map(int,input().split())) h=n[0] s=n[-1] udzl=input() for i in udzl: if i=="u": if s>0: s=s-1 else: if s<h: s=s+1 print(s)
- 1
Information
- ID
- 10599
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By