No Rules Rules

다이얼 (feat. 백준, 5622번) 본문

생활/코테

다이얼 (feat. 백준, 5622번)

개발하는 완두콩 2022. 8. 11. 21:04
728x90
반응형

다이얼
https://www.acmicpc.net/problem/5622

 

5622번: 다이얼

첫째 줄에 알파벳 대문자로 이루어진 단어가 주어진다. 단어의 길이는 2보다 크거나 같고, 15보다 작거나 같다.

www.acmicpc.net

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <string.h>
using namespace std;
int get_number(char tmp) {
	if ('A' <= tmp && tmp <= 'C')
		return 2;
	else if ('D' <= tmp && tmp <= 'F')
		return 3;
	else if ('G' <= tmp && tmp <= 'I')
		return 4;
	else if ('J' <= tmp && tmp <= 'L')
		return 5;
	else if ('M' <= tmp && tmp <= 'O')
		return 6;
	else if ('P' <= tmp && tmp <= 'S')
		return 7;
	else if ('T' <= tmp && tmp <= 'V')
		return 8;
	return 9;
}
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	register int ans = 0;
	string str;
	cin >> str;
	for (register int i = 0; i < str.size(); ++i)
		ans += get_number(str.at(i)) + 1;
	cout << ans;
	return 0;
}
// *&)*@*
  1. 알파벳에 해당하는 번호를 가지고 옵니다.
  2. 그리고 매 번호마다 1을 더해줍니다. 왜냐하면 문제의 조건처럼 '한 칸 옆에 있는 숫자를 걸기 위해선 1초씩 더 걸린다' 이기 때문입니다.
728x90
반응형
Comments