본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 18698 : The Walking Adam

반응형

https://www.acmicpc.net/problem/18698

 

18698번: The Walking Adam

Adam has just started learning how to walk (with some help from his brother Omar), and he falls down a lot. In order to balance himself, he raises his hands up in the air (that’s a true story), and once he puts his hands down, he falls. You are given a s

www.acmicpc.net

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

test case t, 정답 ans, 문자열 s를 선언 후 입력받습니다.

📔 풀이과정

D또는 문자열의 마지막까지 'U'의 개수를 세줍니다. 이 값을 ans에 더해줍니다.

📔 정답출력

ans를 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int t, ans;
string s;
int main(){
  cin >> t;
  while(t--){
    ans = 0;
    cin >> s;
    for(auto c : s){
      if(c == 'D') break;
      ans++;
    }
    cout << ans << '\n';
  }
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.