백준 5622 c++

magicdrill·2024년 3월 19일
0

백준 문제풀이

목록 보기
175/655

백준 5622 c++

#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

int main(void)
{
	char phoneStr[16];
	int* phoneStrtoInt;
	int i, temp, len, totalTime = 0;

	cin >> phoneStr;
	len = (int)strlen(phoneStr);
	if (len >= 2 && len <= 15)
	{
		phoneStrtoInt = new int[len];
	}
	else
	{
		return 0;
	}
	for (i = 0; i < len; i++)
	{
		temp = (int)phoneStr[i];
		if (temp >= 65 && temp <= 67) //ABC
		{
			phoneStrtoInt[i] = 2;
		}
		else if (temp >= 68 && temp <= 70) //DEF
		{
			phoneStrtoInt[i] = 3;
		}
		else if (temp >= 71 && temp <= 73) //GHI
		{
			phoneStrtoInt[i] = 4;
		}
		else if (temp >= 74 && temp <= 76) //JKL
		{
			phoneStrtoInt[i] = 5;
		}
		else if (temp >= 77 && temp <= 79) //MNO
		{
			phoneStrtoInt[i] = 6;
		}
		else if (temp >= 80 && temp <= 83) //PQRS
		{
			phoneStrtoInt[i] = 7;
		}
		else if (temp >= 84 && temp <= 86) //TUV
		{
			phoneStrtoInt[i] = 8;
		}
		else //WXYZ
		{
			phoneStrtoInt[i] = 9;
		}
		totalTime = totalTime + phoneStrtoInt[i] + 1;
	}

	cout << totalTime << endl;

	delete[] phoneStrtoInt;
	return 0;
}

0개의 댓글