티스토리 뷰

1152번: 단어의 개수
https://www.acmicpc.net/problem/1152
#include <iostream>
#include <string>
using namespace std;

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

	int count = 0;
	int check = false;
	string inputString;
	
	getline(cin, inputString);
	
	int stringLength = inputString.length();

	if (stringLength == 0)
	{
		cout << count;
	}

	else
	{
		for (int i = 0; i < stringLength; i++)
		{
			if (inputString[i] != ' ' && check == false)
			{
				check = true;
				count++;
			}
			else if (inputString[i] == ' ')
			{
				check = false;
			}
		}

		cout << count;
	}
}
메모리 (KB)시간 (ms)코드 길이 (B)
36808555

Uploaded by N2T

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
링크
Total
Today
Yesterday