用 C++ 将句子转换成它等效的移动数字键盘序列
在本教程中,我们将讨论程序,来将句子转换为其等效的移动数字键盘序列。
为此,我们将提供一个由字母字符组成的字符串。我们的任务是打印字符串的数字等价,即键入特定字符串的数字序列。
示例
#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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP