4、电话分身

题目描述

继MIUI8推出手机分身功能之后,MIUI9计划推出一个电话号码分身的功能:首先将电话号码中的每个数字加上8取个位,然后使用对应的大写字母代替 ("ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"), 然后随机打乱这些字母,所生成的字符串即为电话号码对应的分身。

输入描述:

第一行是一个整数T(1 ≤ T ≤ 100)表示测试样例数;接下来T行,每行给定一个分身后的电话号码的分身(长度在3到10000之间)。

输出描述:

输出T行,分别对应输入中每行字符串对应的分身前的最小电话号码(允许前导0)。

示例1

示例1

输入

4
EIGHT
ZEROTWOONE
OHWETENRTEO
OHEWTIEGTHENRTEO

输出

0
234
345
0345

解法一:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
     int t;
     char n[10004];
     int b[10] = {0,0,0,0,0,0,0,0,0,0};
     int i,j,k,s;
     scanf ( "%d" ,&t);
     while (t--) {
         memset (b,0, sizeof (b));
         scanf ( "%s" ,&n);
         s =  strlen (n);
         for (i = 0; i< s; i++) {
             if (n[i] ==  'Z' ) b[0]++; //0对应2
             if (n[i] ==  'O' ) b[1]++;
             if (n[i] ==  'W' ) b[2]++; //2对应4
             if (n[i] ==  'H' ) b[3]++;
             if (n[i] ==  'U' ) b[4]++; //4对应6
             if (n[i] ==  'F' ) b[5]++;
             if (n[i] ==  'X' ) b[6]++; //6对应8
             if (n[i] ==  'S' ) b[7]++;
             if (n[i] ==  'G' ) b[8]++; //8对应0
             if (n[i] ==  'I' ) b[9]++;
         }
         b[1] = b[1] - b[0] - b[2] - b[4]; //1对应3
         b[3] = b[3] - b[8]; //3对应5
         b[5] = b[5] - b[4]; //5对应7
         b[7] = b[7] - b[6]; //7对应9
         b[9] = b[9] - b[8] - b[5]- b[6]; //9对应1
         while (b[8]--) {
             printf ( "%c" , '0' );
         }
         while (b[9]--) {
             printf ( "%c" , '1' );
         }
         while (b[0]--) {
             printf ( "%c" , '2' );
         }
         while (b[1]--) {
             printf ( "%c" , '3' );
         }
         while (b[2]--) {
             printf ( "%c" , '4' );
         }
         while (b[3]--) {
             printf ( "%c" , '5' );
         }
         while (b[4]--) {
             printf ( "%c" , '6' );
         }
         while (b[5]--) {
             printf ( "%c" , '7' );
         }
         while (b[6]--) {
             printf ( "%c" , '8' );
         }
         while (b[7]--) {
             printf ( "%c" , '9' );
         }
         printf ( "\n" );
     }
}

解法二: 

#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
     int i = 0, j = 0;
     int n;
     while (cin >> n){
         string s;  
         for (i = 0; i < n; i++){
             cin >> s;
             vector< int > iimap(256);
             for (j = 0; j < s.size(); j++){
                 iimap[s[j]]++;
             }
             vector< int > res(10);
             int count = iimap[ 'U' ];
             res[6] = count;
             iimap[ 'F' ] -= count;
             iimap[ 'O' ] -= count;
             iimap[ 'U' ] -= count;
             iimap[ 'R' ] -= count;
 
             count = iimap[ 'X' ];
             res[8] = count;
             iimap[ 'S' ] -= count;
             iimap[ 'I' ] -= count;
             iimap[ 'X' ] -= count;
 
             count = iimap[ 'W' ];
             res[4] = count;
             iimap[ 'T' ] -= count;
             iimap[ 'W' ] -= count;
             iimap[ 'O' ] -= count;
 
             count = iimap[ 'G' ];
             res[0] = count;
             iimap[ 'E' ] -= count;
             iimap[ 'I' ] -= count;
             iimap[ 'G' ] -= count;
             iimap[ 'H' ] -= count;
             iimap[ 'T' ] -= count;
 
             count = iimap[ 'Z' ];
             res[2] = count;
             iimap[ 'Z' ] -= count;
             iimap[ 'E' ] -= count;
             iimap[ 'R' ] -= count;
             iimap[ 'O' ] -= count;
 
             count = iimap[ 'F' ];
             res[7] = count;
             iimap[ 'F' ] -= count;
             iimap[ 'I' ] -= count;
             iimap[ 'V' ] -= count;
             iimap[ 'E' ] -= count;
 
             count = iimap[ 'V' ];
             res[9] = count;
             iimap[ 'S' ] -= count;
             iimap[ 'E' ] -= count;
             iimap[ 'V' ] -= count;
             iimap[ 'E' ] -= count;
             iimap[ 'N' ] -= count;
 
             count = iimap[ 'T' ];
             res[5] = count;
             iimap[ 'T' ] -= count;
             iimap[ 'H' ] -= count;
             iimap[ 'R' ] -= count;
             iimap[ 'E' ] -= count;
             iimap[ 'E' ] -= count;
 
             count = iimap[ 'O' ];
             res[3] = count;
             iimap[ 'O' ] -= count;
             iimap[ 'N' ] -= count;
             iimap[ 'E' ] -= count;
 
             count = iimap[ 'I' ];
             res[1] = count;
             iimap[ 'N' ] -= count;
             iimap[ 'I' ] -= count;
             iimap[ 'N' ] -= count;
             iimap[ 'E' ] -= count;
 
             for ( int k = 0; k < res.size(); k++){
                 for ( int l = 0; l < res[k]; l++)
                     cout << k;
             }
             cout << endl;
         }
     }
     return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值