Baekjoon #20436

Baekjoon #20436

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
#include<bits/stdc++.h>

using namespace std;

const string qwerty[3] = {"qwertyuiop", "asdfghjkl", "zxcvbnm"};
const string OnlyLeft  = "qwertasdfgzxcv";
int X[33], Y[33];

bool isLeft(char x){ return OnlyLeft.find(x) != string::npos; }
int dist(char a, char b){return abs(Y[a-'a']-Y[b-'a']) + abs(X[a-'a']-X[b-'a']); }

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    for(int i=0;i<3;i++){
        for(int j=0;j<(int)qwerty[i].size();j++){
            Y[qwerty[i][j] - 'a'] = i;
            X[qwerty[i][j] - 'a'] = j;
        }
    }

    char L, R; cin >> L >> R;
    string word; cin >> word;

    int answer = 0;
    for(auto &w: word){
        if(isLeft(w)) {
            answer += dist(L, w) + 1;
            L = w;
        }
        else {
            answer += dist(R, w) + 1;
            R = w;
        }
    }
    cout << answer;

    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.