2013
12-26

Kaitou Kid – The Phantom Thief (1)

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.

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.

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

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

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define LL long long
#define maxint 2147483647
#define maxll 9223372036854775807
#define dg cout << "Here!" << endl;
using namespace std;

int main()
{
int C, i, len;
char s[10001], ch;
scanf("%d", &C);
while(C--)
{
scanf("%s", s);
len = strlen(s);
for(i = 0; i < len; i++)
{
if(s[i] >= '0' && s[i] <= '9')
{
if(s[i+1] == '-' || s[i+1] == '\0')
{
//ch = s[i] + 'A' - '1';
putchar(s[i] + 'A' - '1');
i++;
}
else if(s[i+1] >= '0' && s[i+1] <='9')
{
//ch = (s[i] - '0')*10 + s[i+1] - '0' + 'A' - 1;
putchar((s[i] - '0')*10 + s[i+1] - '0' + 'A' - 1);
i++;
}
else putchar(s[i] + 'A' - '1');
}
else if(s[i] == '#')
putchar(' ');

}
puts("");
}
return 0;
}

1. 有限自动机在ACM中是必须掌握的算法，实际上在面试当中几乎不可能让你单独的去实现这个算法，如果有题目要用到有限自动机来降低时间复杂度，那么这种面试题应该属于很难的级别了。

2. 第23行：
hash = -1是否应该改成hash[s ] = -1

因为是要把从字符串s的start位到当前位在hash中重置

修改提交后能accept，但是不修改居然也能accept