티스토리 뷰

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

 

2037번: 문자메시지

문제 오른쪽 그림과 같은 핸드폰 자판이 있다. 이 자판을 이용하여 어떤 영어 메시지를 치려고 할 때, 걸리는 최소 시간을 구하는 프로그램을 작성하시오. 단, 1번은 누를 경우에는 공백이 찍힌��

www.acmicpc.net

 

 

구현 문제!

 

 

 

#include <iostream>
#include <string>
#include <cctype>

using namespace std;


char group[8][2] = {{'A', 'C'}, {'D', 'F'}, {'G', 'I'}, {'J', 'L'}, {'M', 'O'}, {'P', 'S'}, {'T', 'V'}, {'W', 'Z'}};

int main() {
    int p, w;
    string str;
    cin >> p >> w;
    cin.ignore();
    getline(cin, str);

    int before = -1;
    int cnt = 0;
    bool flag = false;
    int ret = 0;

    for(int i = 0; i < str.size(); i++) {
        char temp = str[i];

        if(isalpha(temp)) {
            for(int j = 0; j < 8; j++) {
                if(temp >= group[j][0] && temp <= group[j][1]) {
                    if(before == j) flag = true;

                    cnt = (temp - group[j][0] + 1) * p;
                    before = j;
                }
            }
        } else {
            cnt = p;
            before = -1;
        }

        if(flag) cnt += w;
        ret += cnt;

        flag = false;
    }

    cout << ret;

    return 0;
}

 

 

 

개발 환경 : vscode

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

 

'알고리즘 > 백준(BOJ)' 카테고리의 다른 글

백준 - 10217 KCM Travel  (2) 2020.06.22
백준 - 11404 플로이드  (0) 2020.06.21
백준 - 3568 iSharp  (0) 2020.06.21
백준 - 1174 줄어드는 숫자  (0) 2020.06.16
백준 - 11657 타임머신  (0) 2020.06.16
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함