본문 바로가기

알고리즘/백준

다이얼

#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[16] = { 0 }; // 배열 생성
	int time[] = { 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6,
		7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10 }; //알파벳에 따른 시간
	int res = 0;

	scanf("%s", str); 

	for (int i = 0; i < strlen(str); i++)
		res += time[str[i] - 'A'];

	printf("%d \n", res);
	return 0;
}
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	char str[16] = { 0 };
	int time[] = { 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6,
		7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10 };
	int res = 0;

	cin >> str;
	
	for (int i = 0; i < strlen(str); i++)
		res += time[str[i] - 'A'];

	cout << res << '\n';
	return 0;
}

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

그룹 단어 체커  (0) 2019.10.24
크로아티아 알파벳  (0) 2019.10.22
상수  (0) 2019.10.16
단어의 개수  (0) 2019.10.14
단어 공부  (0) 2019.10.12