admin管理员组文章数量:1534198
线上编程体验活动地址:https://www.nowcoder/activity/2018tw/index
题目我忘记了,大致意思是:
输入任意数字,打印出相对应得字符
例如:
不多说了直接上题解吧
import java.util.Scanner;
import java.util.Stack;
public class ThoughtWorks_test {
public static void main(String []args){
Scanner sc=new Scanner(System.in);
String n=sc.nextLine();
String a[]={"._.\n|.|\n|_|",
"...\n..|\n..|",
"._.\n._|\n|_.",
"._.\n._|\n._|",
"...\n|_|\n..|",
"._.\n|_.\n._|",
"._.\n|_.\n|_|",
"._.\n..|\n..|",
"._.\n|_|\n|_|",
"._.\n|_|\n..|"};
char N[]=n.toCharArray();
{
Stack<Long> stack = new Stack<>();
int count = N.length;
for (int i=count-1;i>=0;i--){
stack.push((long) (N[i]-'0'));
}
String S[][] = new String[count + 1][];
for (int i = 0; i < count; i++) {
S[i] = a[Math.toIntExact(stack.pop())].split("\n");
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < count; j++)
if (j == count - 1)
System.out.print(S[j][i]);
else System.out.print(S[j][i] + " ");
System.out.println();
}
}
}
}
解析:
应该不算难,代码也相对比较得的简陋无非就是将0-9这十个字符中的每一个字符都用字符数组来表示,这样就有一个长度为10的二维字符数组,然后再利用for和if轻松的将其打印出来
小结
调试花了半个小时,题目虽然简单,但探险的过程还是花了不少的时间
本文标签: 题解线上thoughtworks
版权声明:本文标题:ThoughtWorks线上编程题解体验 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1726877213a1088489.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论