※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 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

각 테스트케이스마다 문자열을 하나씩 읽어, 그 문자열을 첫 문자부터 살펴보면서 'U'이면 답을 1 증가시키고 아니면 살펴보기를 중단하는 것으로 문제를 해결할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

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

	int T; cin >> T;
	while (T--) {
		int ans = 0;
		string s; cin >> s;
		for (auto& l : s) {
			if (l == 'U') ans++;
			else break;
		}

		cout << ans << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 25625 // C++] 샤틀버스  (0) 2022.10.30
[BOJ 25372 // C++] 성택이의 은밀한 비밀번호  (0) 2022.10.30
[BOJ 4696 // C++] St. Ives  (0) 2022.10.30
[BOJ 18198 // C++] Basketball One-on-One  (0) 2022.10.30
[BOJ 25600 // C++] Triathlon  (0) 2022.10.30

+ Recent posts