IBM Minus One (hdoj 1.2.7)

Problem Description

You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only two men are awake, and the ship is controlled by the intelligent computer HAL. But during the flight HAL is acting more and more strangely, and even starts to kill the crew on board. We don't tell you how the story ends, in case you want to read the book for yourself :-)

After the movie was released and became very popular, there was some discussion as to what the name 'HAL' actually meant. Some thought that it might be an abbreviation for 'Heuristic ALgorithm'. But the most popular explanation is the following: if you replace every letter in the word HAL by its successor in the alphabet, you get ... IBM.

Perhaps there are even more acronyms related in this strange way! You are to write a program that may help to find this out.

 

Input

The input starts with the integer n on a line by itself - this is the number of strings to follow. The following n lines each contain one string of at most 50 upper-case letters.

 

Output

For each string in the input, first output the number of the string, as shown in the sample output. The print the string start is derived from the input string by replacing every time by the following letter in the alphabet, and replacing 'Z' by 'A'.

Print a blank line after each test case.

 

Sample Input

2
HAL
SWERC

 

Sample Output

String #1
IBM

String #2
TXFSD

 

 

Source

Southwestern Europe 1997, Practice

 

Recommend

Ignatius.L

 

翻譯版


你可能聽說過Arthur C. Clarke的書“2001 - A Space Odyssey”,或者是Stanley Kubrick的同名電影。其中有一艘宇宙飛船從地球發送到土星。機組人員因長途飛行而陷入停滯狀態,只有兩名男子醒來,船隻由智能電腦HAL控制。但是在飛行過程中,HAL的行動越來越奇怪,甚至開始殺死船上的船員。我們不會告訴你這個故事是如何結束的,如果你想爲自己閱讀這本書:-)

在電影上映並變得非常受歡迎之後,人們就“HAL”這個名字的實際含義進行了一些討論。有些人認爲它可能是“啓發式算法”的縮寫。但最流行的解釋如下:如果你用字母表中的繼承者替換單詞HAL中的每個字母,你就得到...... IBM。

也許有更多的縮略詞以這種奇怪的方式相關!你要編寫一個可能有助於找到它的程序。

 

輸入

輸入以行上的整數n開始 - 這是要遵循的字符串數。以下n行每行包含一個最多50個大寫字母的字符串。

 

產量

對於輸入中的每個字符串,首先輸出字符串的編號,如示例輸出中所示。打印字符串start是從輸入字符串派生的,每次都用字母表中的後續字母替換,並將'Z'替換爲'A'。

在每個測試用例後打印一個空行。

 

樣本輸入

2 
HAL 
SWERC

 

樣本輸出

字符串#1 
IBM 

String#2 
TXFSD

 

 

資源

西南歐1997年,實踐

 

推薦

Ignatius.L

這道題我用了map來存儲字母的下一位直接用Mymap[ AT [ i ] ]就讀取字母下一位

#include<iostream>
#include<stdio.h>
#include<map>
#include<string.h>
using namespace std; 
int main(){
	map<char,char>Mymap;
	Mymap['A']='B';
	Mymap['B']='C';
	Mymap['C']='D';
	Mymap['D']='E';
	Mymap['E']='F';
	Mymap['F']='G';
	Mymap['G']='H';
	Mymap['H']='I';
	Mymap['I']='J';
	Mymap['J']='K';
	Mymap['K']='L';
	Mymap['L']='M';
	Mymap['M']='N';
	Mymap['N']='O';
	Mymap['O']='P';
	Mymap['P']='Q';
	Mymap['Q']='R';
	Mymap['R']='S';
	Mymap['S']='T';
	Mymap['T']='U';
	Mymap['U']='V';
	Mymap['V']='W';
	Mymap['W']='X';
	Mymap['X']='Y';
	Mymap['Y']='Z';
	Mymap['Z']='A';
	int n,x=1;
	scanf("%d",&n);
	while(n--){
		char AT[999];
		scanf("%s",AT);
		int len=strlen(AT);
		printf("String #%d\n",x++);
		for(int i=0;i<len;i++){
			printf("%c",Mymap[AT[i]]);
		}
			printf("\n\n");	

	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章