728x90
C++ 코드)
#include <iostream>
#include <string>
using namespace std;
int dial(char c)
{
int result;
switch(c)
{
case 'A':
case 'B':
case 'C':
result=2;
break;
case 'D':
case 'E':
case 'F':
result=3;
break;
case 'G':
case 'H':
case 'I':
result=4;
break;
case 'J':
case 'K':
case 'L':
result=5;
break;
case 'M':
case 'N':
case 'O':
result=6;
break;
case 'P':
case 'Q':
case 'R':
case 'S':
result=7;
break;
case 'T':
case 'U':
case 'V':
result=8;
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
result=9;
break;
}
return result;
}
int main()
{
string str;
int res=0;
cin>>str;
for(int i=0;i<str.length();i++)
{
res+=dial(str[i]);
res++;
}
cout<<res;
return 0;
}
함수 하나 맹글고, 거기서 string 원소 한개씩 함수로 다이얼 숫자 불러옴
여기서 switch case로 구분해서 쓴다
그러고 1씩 더해줘서 나중에 출력하면 끝!
얼른 과제 끝내고 어려운 코테 대비 한번 해보자!!
728x90
'코딩테스트 > BOJ' 카테고리의 다른 글
1316번 그룹 단어 체커 (0) | 2021.12.18 |
---|---|
1065번 한수 (0) | 2021.12.17 |
4673번 셀프 넘버 (0) | 2021.12.15 |
2750번 수 정렬하기 (0) | 2021.12.14 |
1157번 단어 공부 (0) | 2021.12.12 |
댓글