HDU 1982 字符串模拟 水题

Do you know Kaitou Kid? In the legend, Kaitou Kid is a master of disguise, and can take on the voice and form of anyone. He is not an evil person, but he is on the wrong side of the law. He’s the very elusive phantom thief who never miss his prey although he always uses word puzzles to announce his targets before action.

You are the leader of a museum. Recently, you get several priceless jewels and plan to hold an exhibition. But at the moment, you receive Kid’s word puzzle… Fortunately, It seems Kid doesn’t want to trouble you, and his puzzle is very easy. Just a few minutes, You have found the way to solve the puzzle:

(1) change 1 to ‘A’, 2 TO ‘B’,…,26 TO ‘Z’
(2) change ‘#’ to a blank
(3) ignore the ‘-’ symbol, it just used to separate the numbers in the puzzle

Input
The first line of the input contains an integer C which means the number of test cases. Then C lines follow. Each line is a sentence of Kid’s word puzzle which is consisted of ‘0’ ~ ‘9’ , ‘-’ and ‘#’. The length of each sentence is no longer than 10000.

Output
For each case, output the translated text.

Sample Input
4
9#23-9-12-12#19-20-5-1-12#1-20#12-5-1-19-20#15-14-5#10-5-23-5-12
1-14-4#12-5-1-22-5#20-8-5#13-21-19-5-21-13#9-14#20#13-9-14-21-20-5-19
1-6-20-5-18#20-8-5#15-16-5-14-9-14-7#15-6#20-8-5#5-24-8-9-2-9-20-9-15-14
7-15-15-4#12-21-3-11

Sample Output
I WILL STEAL AT LEAST ONE JEWEL
AND LEAVE THE MUSEUM IN T MINUTES
AFTER THE OPENING OF THE EXHIBITION
GOOD LUCK

ACcode:

#include <bits/stdc++.h>
using namespace std;
string str[10010];
string str1[10010];
int main ()
{
    int n;
    while(cin>>n)
    {
        for(int i=0;i<10010;i++)
        {
            str[i]="";
            str1[i]="";
        }
        for(int i=0;i<n;i++)
        {
            cin>>str[i];
            str[i]+='-';
        }
        int sum=0;
        for(int i= 0;i<n;i++)
        {

            for(int j=0;j<str[i].length();j++)
            {
                if((str[i][j]>='0' && str[i][j]<='9') || str[i][j]=='#')
                {
                    if(str[i][j]>='0' && str[i][j]<='9')
                    {
                      sum=sum*10+str[i][j]-'0';
                      if(!(str[i][j+1]>='0' && str[i][j+1]<='9'))
                      {
                          str1[i]+=('A'+sum-1);
                          sum=0;
                      }
                    }
                    else
                        str1[i]+=' ';
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<str1[i].length();j++)
            {
                    cout<<str1[i][j];
            }
            puts("");
        }
    }
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值