1152: 단어의 개수

Jimin·2022년 11월 29일
0

알고리즘

목록 보기
26/71

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

#include <iostream>
#include <string>

using namespace std;

bool check(char e);

int main(){
    string str;
    getline(cin, str);
    int cnt=0;
    for(int i=0;i<str.length()-1;i++){
        if(str[i] == ' ' && check(str[i+1])) { // 오른쪽이 알파벳 왼쪽이 빈칸
            cnt++;
        }
    }
    if(check(str[0])) cnt++;
    cout << cnt <<endl;
    return 0;
}

bool check(char e) {
    return e>='a' && e<='z' || e>='A' && e<='Z';
}
profile
https://github.com/Dingadung

0개의 댓글