이 튜토리얼에서는 문장을 상응하는 모바일 숫자 키패드 시퀀스로 변환하는 프로그램에 대해 논의할 것입니다.
이를 위해 알파벳 문자열이 제공됩니다. 우리의 임무는 문자열에 해당하는 숫자, 즉 특정 문자열을 입력하기 위한 키의 숫자 시퀀스를 인쇄하는 것입니다.
예시
#include <bits/stdc++.h>
using namespace std;
//computing the numerical sequence
string calc_sequence(string arr[], string input){
string output = "";
//length of input string
int n = input.length();
for (int i=0; i<n; i++){
//checking if space is present
if (input[i] == ' ')
output = output + "0";
else {
int position = input[i]-'A';
output = output + arr[position];
}
}
return output;
}
int main(){
//storing the sequence in array
string str[] = {
"2","22","222",
"3","33","333",
"4","44","444",
"5","55","555",
"6","66","666",
"7","77","777","7777",
"8","88","888",
"9","99","999","9999"
};
string input = "TUTORIALSPOINT";
cout << calc_sequence(str, input);
return 0;
} 출력
8888666777444255577777666444668