HDU - 1982 Kaitou Kid - The Phantom Thief

HDU - 1982 Kaitou Kid - The Phantom Thief

传送门

问题描述:

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

输入说明:

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.

输出说明:

For each case, output the translated text.

思路:

一点点读入数据即可,#是空格,-直接忽略,数字的读入要进行一点点小的处理,注意换行和输出的都是大写字母,真的挺简单的一道题,按照题目意思一步步来即可

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int T;
	cin>>T;
	getchar();
	while (T--)
	{
    
    
		char s[10001];
		int len,i;
		cin.getline(s,10001);
		len=strlen(s);
		for (i= 0;i<len;i++)
		{
    
    
			string t;
			t=t+s[i]+s[i+1];
			if (((t[0]>='0')&&(t[0]<='9')) && ((t[1]>='0')&&(t[1]<='9')))
			{
    
    
				int a=(t[0]-'0')*10+(t[1]-'0');//先将字符转换为数字,再将数字转换成字母,利用ascall码进行操作
				char ch=a-1+'A';
				cout<<ch;
				i++;
			}
			else if (s[i]=='#')
			{
    
    
				cout<<' ';
			}
			else if (s[i]=='-')
			{
    
    
				continue;
			}
			else
			{
    
    
				char k=s[i]-'0'-1+'A';
				cout<<k;
			}
		}
		cout<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_51727949/article/details/114445287
今日推荐