프로그래밍/BOJ

백준 알고리즘 [5622번] (C++) 다이얼

coty 2019. 7. 29. 20:09


Code

#include <iostream>
using namespace std;

#define MAX 15

int main() {
	ios::sync_with_stdio(NULL);
	cin.tellg();

	char p[MAX] = { 0, };
	int time = 0;

	cin >> p;

	for (int i = 0; p[i]; i++) {
		if (p[i] >= 'A' && p[i] <= 'Z') {
			if (p[i] <= 'C') time += 3;
			else if (p[i] <= 'F') time += 4;
			else if (p[i] <= 'I') time += 5;
			else if (p[i] <= 'L') time += 6;
			else if (p[i] <= 'O') time += 7;
			else if (p[i] <= 'S') time += 8;
			else if (p[i] <= 'V') time += 9;
			else if (p[i] <= 'Z') time += 10;
		}
		else {
			cout << "대문자가 아닌 문자가 있습니다.";
			return 0;
		}
	} // for
	cout << time;
}