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);
}
}
}
HDOJ/HDU 1982 Kaitou Kid - The Phantom Thief (1)(字符串处理)的更多相关文章
- 【HDOJ】1983 Kaitou Kid - The Phantom Thief (2)
不仅仅是DFS,还需要考虑可以走到终点.同时,需要进行预处理.至多封闭点数为起点和终点的非墙壁点的最小值. #include <iostream> #include <cstdio& ...
- HDU 1983 Kaitou Kid - The Phantom Thief (2)
神题,搜索太差,来自网络的题解与程序 思路: 封锁出口或者入口周围的格子. 最多需要4个封锁点. 所以我们可以采取这样的策略: 1.寻找一条盗贼的可行路线,如果没有,返回0. 2.计算封锁出口和入口四 ...
- HDU——1982Kaitou Kid - The Phantom Thief (1)(坑爹string题)
Kaitou Kid - The Phantom Thief (1) Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/327 ...
- HDOJ/HDU 1088 Write a simple HTML Browser(HTML字符串)
Problem Description If you ever tried to read a html document on a Macintosh, you know how hard it i ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
随机推荐
- 01_JavaMail_01_邮件服务器简述
[收发邮件简单流程] 过程大致是: 发邮件时从客户端发邮件发送到邮件服务器,收邮件就是把邮件服务器的邮件下载到客户端. [邮件协议] * SMTP:(Simple Mail Transfer Prot ...
- 简单的一个makefile
cpp_obj = $(patsubst %.cpp, %.o, $(wildcard *.cpp)) bin : $(cpp_obj) g++ -o bin $(cpp_obj) .PHONY : ...
- Python之实现一个简易计算器
自己动手写计算器 一.功能分析 用户输入一个类似这样 3*( 4+ 50 )-(( 100 + 40 )*5/2- 3*2* 2/4+9)*((( 3 + 4)-4)-4) 这样的表达式,假设表达式里 ...
- ASP.NET 优化 check list
看到一个蛮有意思的网站,里面有针对asp.net方方面面优化的罗列: 点击打开链接http://webdevchecklist.com/asp.net/performance/ 点击打开链接http: ...
- 动态改变EasyUI grid 列宽和隐藏列
隐藏显示 $('#yourGrid').datagrid('hideColumn','yourColumn'); $('#yourGrid').datagrid('hideColumn','yourC ...
- Mock相关收集
MockMVC+Mockito http://www.cnblogs.com/syxchina/p/4150879.html Spring中使用Mockito http://www.cnblogs.c ...
- yii2 ActiveRecord常用用法
User::find()->all(); 返回所有数据 User::findOne($id); 返回 主键 id=1 的一条数据 User::find()->where ...
- windows下的SASS/Compass的安装与卸载
认识SASS/Compass SASS是一种CSS的开发工具,提供了许多便利的写法,大大节省了设计者的时间,使得CSS的开发,变得简单和可维护. SASS与Compass的安装说明 SASS在Wind ...
- 学一点 mysql 双机异地热备份----快速理解mysql主从,主主备份原理及实践
双机热备的概念简单说一下,就是要保持两个数据库的状态 自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做的好处多. 1. 可以做灾备,其中一个坏了可以切换 ...
- LeetCode【第217题】Contains Duplicate
题目: ''' Given an array of integers, find if the array contains any duplicates. Your function should ...