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

[C++] 백준 2648: Gum Gum for Jay Jay

by 코딩고수이고파 2023. 3. 13.

문제

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

 

26489번: Gum Gum for Jay Jay

You are lost in the museum and keep walking by a giant rock head that says “gum gum for jay jay” each time you walk by. Print out the number of times you have walked by the giant rock head after reading in the data file.

www.acmicpc.net

 

해결 방법

C++는 string 헤더의 getline을 사용해서 공백까지 입력받을 수 있다.

string s;
getline(cin,s);

글자가 어떤지는 상관없고 몇번의 줄바꿈이 발생했는지만 세주면 된다.

 

코드

#include<iostream>
#include<string>

using namespace std;

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

	string s;
	int res = 0;
	while (getline(cin, s)) {
		res++;
	}

	cout << res;

	return 0;
}

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

[Visual Basic] 백준 14337: Helicopter  (0) 2023.03.15
[FreeBASIC] 백준 2377: Pottery  (0) 2023.03.14
[C++] 백준 1912: 연속합  (0) 2022.07.12
[C++] 백준 2109번: 순회강연  (0) 2021.11.01
[C++] 백준 1946: 신입사원  (0) 2021.11.01

댓글