题目来源:ASCII Art
要求
- 将输入的A-Z,a-z字符转成给出的ASCII样式
- 其余字符转成 “?”(位于给出样式最后)
思路
- 将输入要转换字符都转成大写
- 将转换后的字符串通过与“A”的ASCII码进行运算,得到差存入数组list
- 将字符ASCII样式也存入数组ascii_list
- 根据list中的ASCII值与输出字符宽L进行运算得出位置,逐个,逐行输出
代码
import java.util.*;
import java.io.*;
import java.math.*;
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int L = in.nextInt();
int H = in.nextInt();
if (in.hasNextLine()) {
in.nextLine();
}
String T = in.nextLine().toUpperCase();
List<String> ascii_list = new ArrayList<>();
for (int i = 0; i < H; i++) {
String ROW = in.nextLine();
ascii_list.add(ROW);
}
int A = Integer.valueOf('A');
List<Integer> list = new ArrayList<>();
for(int i =0;i<T.length();i++){
if(T.charAt(i)>='A' && T.charAt(i)<='Z')
list.add(Integer.valueOf(T.charAt(i)-A));
else
//其余字符处理
list.add((ascii_list.get(1).length()-L)/L);
}
for(int j=0;j<H;j++){
for(int i=0;i<T.length();i++){
System.out.print(ascii_list.get(j).substring(list.get(i)*L,list.get(i)*L+L));
}
System.out.println();
}
}
}
示例
# ## ## ## ### ### ## # # ### ## # # # # # ### # ## # ## ## ### # # # # # # # # # # ### ###
# # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # # # # # # # # # #
### ## # # # ## ## # # ### # # ## # ### # # # # ## # # ## # # # # # # ### # # # ##
# # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # ### # # # #
# # ## ## ## ### # ## # # ### # # # ### # # # # # # # # # ## # ### # # # # # # ### #
4
5
MANHATTAN
# # # ### # # # ### ### # ###
### # # # # # # # # # # # # # #
### ### # # ### ### # # ### # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #