Baekjoon 2562
최댓값


QUESTION ❔



CODE ⌨️

#include <iostream>
#include <string>

using namespace std;

string s;
int cnt = 0;

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

	getline(cin, s);

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

	if (s[0] == ' ')
	{
		cnt--;
	}

	if (s[s.length() - 1] == ' ')
	{
		cnt--;
	}

	// cout << s.substr() << endl; // 문자열 전체 추출
	// cout << s.substr(7) << endl; // 8번째 원소부터 추출
	// cout << s.substr(2, 4) << endl; // 3번째 원소부터 5번째까지 추출
	// cout << s.substr(str.find('f')) << endl; // f를 찾은 부분부터 추출

	cout << cnt + 1 << "\n";

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

문자열 관련 문제였다. 실전에서 많이 쓰이는 technic이 있으니 많은 공부를 해야겠다고 느꼈다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.