알고리즘/BOJ

백준 10551번 STROJOPIS

꾸준함. 2018. 9. 16. 02:34

문제 링크입니다: https://www.acmicpc.net/problem/10551


switch문을 적절히 사용하면 쉽게 맞출 수 있는 문제였습니다.


#include <iostream>

#include <string>

using namespace std;

 

int fingers[8];

 

int main(void)

{

        ios_base::sync_with_stdio(0);

        cin.tie(0);

        string s;

        cin >> s;

 

        for (int i = 0; i < s.length(); i++)

        {

                 switch (s[i])

                 {

                 case '1':

                 case 'Q':

                 case 'A':

                 case 'Z':

                         fingers[0]++;

                         break;

                 case '2':

                 case 'W':

                 case 'S':

                 case 'X':

                         fingers[1]++;

                         break;

                 case '3':

                 case 'E':

                 case 'D':

                 case 'C':

                         fingers[2]++;

                         break;

                 case '4':

                 case 'R':

                 case 'F':

                 case 'V':

                 case '5':

                 case 'T':

                 case 'G':

                 case 'B':

                         fingers[3]++;

                         break;

                 case '6':

                 case 'Y':

                 case 'H':

                 case 'N':

                 case '7':

                 case 'U':

                 case 'J':

                 case 'M':

                         fingers[4]++;

                         break;

                 case '8':

                 case 'I':

                 case 'K':

                 case ',':

                         fingers[5]++;

                         break;

                 case '9':

                 case 'O':

                 case 'L':

                 case '.':

                         fingers[6]++;

                         break;

                 default:

                         fingers[7]++;

                         break;

                 }

        }

 

        for (int i = 0; i < 8; i++)

                 cout << fingers[i] << "\n";

        return 0;

}


개발환경:Visual Studio 2017


지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 4673번 셀프 넘버  (0) 2018.09.16
백준 10552번 DOM  (0) 2018.09.16
백준 15753번 Taming the Herd  (0) 2018.09.15
백준 15752번 Hoofball  (0) 2018.09.15
백준 15751번 Teleportation  (0) 2018.09.15