HDOJ/HDU 1982 Kaitou Kid - The Phantom Thief (1)(字符串处理)

简介: HDOJ/HDU 1982 Kaitou Kid - The Phantom Thief (1)(字符串处理)

Problem Description

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



题意:

就是输入数字#和-,数字1-26分别对应A-Z.

#对应空格 -没有含义,就是把数字隔开


注意这一种输入:

1

###—##


两种方法:

一,常规方法:

import java.util.Scanner;
public class Main{
    static char[] STR={'a','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t =sc.nextInt();
        while(t-->0){
            String str=sc.next();
            String s[] = str.split("-");
            for(int i=0;i<s.length;i++){
                String strN = "";
                for(int j=0;j<s[i].length();j++){
                    if(s[i].charAt(j)!='#'){
                        strN+=s[i].charAt(j);
                    }else{
                        if(!strN.equals(""))
                            System.out.print(STR[Integer.parseInt(strN)]);
                        System.out.print(" ");
                        strN="";
                    }
                }
                if(!strN.equals(""))
                    System.out.print(STR[Integer.parseInt(strN)]);
            }
            System.out.println();
        }
    }
}


二:利用Java中的replaceAll()方法:

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t =sc.nextInt();
        while(t-->0){
            String str=sc.next();
            str=str.replaceAll("#", " ");
            for(int i=26;i>=1;i--){
                String a=""+(char)('A'+i-1);
                String b=""+i;
                str=str.replaceAll(b, a);
            }
            str=str.replaceAll("-", "");
            System.out.println(str);
        }
    }
}
目录
相关文章
codeforces 317 A Perfect Pair
我先排除了输出-1的,然后再考虑如何计算最小的步数。我们主要在每一步中最小一个加上另一个就可以了,这是朴素的求法,但可能出现这样的情况 比如 -100000000 1 10000000 这样的话会循环100000000多次,肯定超时,所以我们要加快速度。
54 0
|
机器学习/深度学习 Java
【Java每日一题,dfs】[USACO1.5]八皇后 Checker Challenge
【Java每日一题,dfs】[USACO1.5]八皇后 Checker Challenge
2020 ICPC Asia Taipei-Hsinchu Site Programming Contest H. Optimization for UltraNet (二分+最小生成树+算贡献)
2020 ICPC Asia Taipei-Hsinchu Site Programming Contest H. Optimization for UltraNet (二分+最小生成树+算贡献)
129 0
[UPC] Postfix Evaluation 后缀表达式求值 | 栈的简单应用
题目描述 In a postfix expression, operators follow their operands. For example, [ 5 2 * ] is interpreted as 5 * 2. If there are multiple operators, each operator appears after its last operand. Here are more examples, showing how postfix compares to parenthesized expressions:
115 0
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
143 0
大声说出你对女神的爱!Geek is A choice. Girls make difference.
女王节来了,我们采访了来自于阿里云智能一线的6位geek girl,用两天的时间近距离观察她们快乐工作的,还在银泰百货的支持下绽放她们认真生(chou)活(mei)的光芒。 雏恬 我不想做被保护的女生,我想做改变世界的极客。
|
机器学习/深度学习 人工智能

热门文章

最新文章