์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[๋ฐฑ์ค€(BOJ)] 10820๋ฒˆ: ๋ฌธ์ž์—ด ๋ถ„์„ (C++)

PROGRAMMING/Algorithm

by koharin 2021. 8. 30. 18:00

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ก ๋ฌธ์ œํ’€์ด ๊ณผ์ •


getline ์‹œ eof๊ฐ€ ์•„๋‹ ๋•Œ๊นŒ์ง€ ์ž…๋ ฅ์„ ๋ฐ›๊ณ , ์ž…๋ ฅ๋ฐ›๋Š” ์ŠคํŠธ๋ง๋งˆ๋‹ค isdigit, islower, isupper, isspace๋กœ ์ˆซ์ž, ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ๊ณต๋ฐฑ ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์นด์šดํŒ…์„ ์ง„ํ–‰ํ–ˆ๋‹ค.

์ž…๋ ฅ๋ฐ›์„ ๋•Œ cin >> ws๊ฐ€ ์•„๋‹Œ cin๋งŒ ํ•ด์•ผ ์ œ๋Œ€๋กœ ๊ณต๋ฐฑ์ด ์นด์šดํŠธ๋œ๋‹ค.

 

 

๐Ÿ’ป  ์ฝ”๋“œ


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string str;
    while(!getline(cin, str).eof()){
        int c_lower=0, c_upper=0, c_num=0, c_space=0;
        for(char c: str){
            if(isdigit(c)) c_num++;
            else if(islower(c)) c_lower++;
            else if(isupper(c)) c_upper++;
            else if(isspace(c)) c_space++;
        }
        printf("%d %d %d %d\n", c_lower, c_upper, c_num, c_space);
    }
}

 

 

๐Ÿ“„  ์ œ์ถœ๊ฒฐ๊ณผ


728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ