본문 바로가기
  • Let's study
PS/백준

백준 18698: The Walking Adam

by 코딩고수이고파 2023. 5. 11.

문제

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

 

해결방법

for문으로 입력받은 문자열을 하나씩 보면서 'D'이기 전까지 U의 개수를 세준다.

 

코드

#include<iostream>
#include<string>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;

	string str;
	while (t--) {
		cin >> str;

		int cnt = 0;
		for (int i = 0; i < str.length(); i++) {
			if (str[i] == 'D')
				break;
			cnt++;
		}

		cout << cnt << '\n';
	}

	return 0;
}

'PS > 백준' 카테고리의 다른 글

[C++] 백준 25784: Easy-to-Solve Expressions  (0) 2023.05.13
[C++] 백준 6887: Squares  (0) 2023.05.12
[C++] 백준 5300: Fill the Rowboats!  (0) 2023.05.10
[C++] 백준 5357: Dedupe  (0) 2023.05.09
[C++] 백준 11257: IT Passport Examination  (0) 2023.05.08

댓글