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

 

이번에 볼 문제는 백준 26489번 문제인 Gum Gum for Jay Jay이다.
문제는 아래 링크를 확인하자.

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

주어지는 입력의 줄 수를 세는 문제이다.

 

getline을 이용해 주어지는 입력을 줄단위로 받을 때마다 줄 수를 세는 변수 cnt를 1씩 증가시키는 것으로 문제를 해결하자.

 

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

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

string s;
int cnt;

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

	while (getline(cin, s)) cnt++;

	cout << cnt;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 26575 // C++] Pups  (0) 2022.12.19
[BOJ 26530 // C++] Shipping  (0) 2022.12.19
[BOJ 2773 // C++] 바깥 삼각형의 중심  (0) 2022.12.18
[BOJ 26264 // C++] 빅데이터? 정보보호!  (0) 2022.12.18
[BOJ 24449 // C++] カーペット (Carpet)  (0) 2022.12.18

+ Recent posts