๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 10820๋ฒˆ - ๋ฌธ์ž์—ด ๋ถ„์„

by dkswnkk 2021. 10. 24.
 

10820๋ฒˆ: ๋ฌธ์ž์—ด ๋ถ„์„

๋ฌธ์ž์—ด N๊ฐœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ๋ฌธ์ž์—ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๊ฐ ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ

www.acmicpc.net

 

#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;

    while (getline(cin, s)) {
        if (s.length() == 0) break; //์ž…๋ ฅ์ด ์—†์„๋•Œ ์ข…๋ฃŒ
        int lower=0, upper = 0, number=0, empty = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] >= 'A' && s[i] <= 'Z') upper++;
            else if (s[i] >= 'a' && s[i] <= 'z') lower++;
            else if (s[i] >= '0' && s[i] <= '9') number++;
            else if (s[i] == ' ') empty++;
        }
        cout << lower << ' ' << upper << ' ' << number << ' ' << empty << '\n';
    }
}

๋Œ“๊ธ€