题目描述
继MIUI8推出手机分身功能之后,MIUI9计划推出一个电话号码分身的功能:首先将电话号码中的每个数字加上8取个位,然后使用对应的大写字母代替 (”ZERO”, “ONE”, “TWO”, “THREE”, “FOUR”, “FIVE”, “SIX”, “SEVEN”, “EIGHT”, “NINE”), 然后随机打乱这些字母,所生成的字符串即为电话号码对应的分身。
输入描述:
第一行是一个整数T(1 ≤ T ≤ 100)表示测试样例数;接下来T行,每行给定一个分身后的电话号码的分身(长度在3到10000之间)。
输出描述:
输出T行,分别对应输入中每行字符串对应的分身前的最小电话号码(允许前导0)。
示例1
输入
4
EIGHT
ZEROTWOONE
OHWETENRTEO
OHEWTIEGTHENRTEO
输出
0
234
345
0345
参考代码
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int n;
string letter;
vector<string> num;
int b[10] = {0};
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> letter;
num.push_back(letter);
}
for (int j = 0; j < num.size(); j++)
{
for (int k = 0; k < num[j].length(); k++)
{
if (num[j][k] == 'Z')
b[0]++; //0对应2
if (num[j][k] == 'O')
b[1]++; //1对应3
if (num[j][k] == 'W')
b[2]++; //2对应4
if (num[j][k] == 'H')
b[3]++; //3对应5
if (num[j][k] == 'U')
b[4]++; //4对应6
if (num[j][k] == 'F')
b[5]++; //5对应7
if (num[j][k] == 'X')
b[6]++; //6对应8
if (num[j][k] == 'S')
b[7]++; //7对应9
if (num[j][k] == 'G')
b[8]++; //8对应0
if (num[j][k] == 'I')
b[9]++; //9对应1
}
b[1] = b[1] - b[0] - b[2] - b[4];
b[3] = b[3] - b[8];
b[5] = b[5] - b[4];
b[7] = b[7] - b[6];
b[9] = b[9] - b[5] - b[6] - b[8];
while (b[8]--)
cout << '0';
while (b[9]--)
cout << '1';
while (b[0]--)
cout << '2';
while (b[1]--)
cout << '3';
while (b[2]--)
cout << '4';
while (b[3]--)
cout << '5';
while (b[4]--)
cout << '6';
while (b[5]--)
cout << '7';
while (b[6]--)
cout << '8';
while (b[7]--)
cout << '9';
memset(b, 0, sizeof(b));
cout << endl;
}
system("pause");
return 0;
}