在C ++中将句子转换为其等效的移动数字小键盘序列
在本教程中,我们将讨论将句子转换为等效的移动数字小键盘序列的程序。
为此,我们将提供一串字母字符。我们的任务是打印与字符串等效的数字,即键入特定字符串的键的数字序列。
示例
#include <bits/stdc++.h>
using namespace std;
//计算数字序列
string calc_sequence(string arr[], string input){
string output = "";
//输入字符串的长度
int n = input.length();
for (int i=0; i<n; i++){
//检查是否存在空间
if (input[i] == ' ')
output = output + "0";
else {
int position = input[i]-'A';
output = output + arr[position];
}
}
return output;
}
int main(){
//将序列存储在数组中
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 = "nhooo";
cout << calc_sequence(str, input);
return 0;
}输出结果
8888666777444255577777666444668
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短