3 条题解
-
2
与创建三鼎OJ的大牛同学相比,我只是个普通的不能在普通,算法上资质平平的人了,我写下的题解没什么精妙的解法,只是截止至写题解的时候我这个普通人对这道题的思维吧,这是我的第一篇题解,希望能帮助到大家,也恳请大家的指导,今后请多指教,谢谢了。
import java.util.Scanner; public class P1002 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[][] strArr = new String[][] { {" "," _ ",}, {" |"," _|","|_|","|_ ","| |"}, {" |","|_ "," _|","|_|"} };//在这个二维数组中存入所有可能出现的字符串 while (sc.hasNextInt()) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); int[] arr = new int[]{a,b,c,d};//将输入存入数组,便于遍历 String temp = ""; //用for循环一行一行输出,i用来确定输出到第几行了,也确定应该调用字符串数组strArr的哪一行字符串(一共三行) for (int i = 0; i < 3; i++) { for(int num : arr)//遍历,筛选,然后把对应的字符串接到temp上(也可以直接不换行输出) { if(i == 0) { if(num == 1 || num == 4) { temp += strArr[i][0]; } else//只是我偷懒,最好还是用else-if吧(下同) { temp += strArr[i][1]; } } if(i == 1) { if(num == 1 || num == 7) { temp += strArr[i][0]; } else if (num == 2 || num == 3) { temp += strArr[i][1]; } else if (num == 0) { temp += strArr[i][4]; } else if (num == 5 || num == 6) { temp += strArr[i][3]; }else { temp += strArr[i][2]; } } if(i == 2) { if(num == 1 || num == 7 || num == 4) { temp += strArr[i][0]; } else if (num == 2) { temp += strArr[i][1]; } else if (num == 0 || num == 6 || num == 8) { temp += strArr[i][3]; } else if (num == 5 || num == 3 || num == 9) { temp += strArr[i][2]; } } } System.out.println(temp);//输出temp temp = "";//重置temp,准备下一行录入 } } } }
信息
- ID
- 3
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 27
- 已通过
- 4
- 上传者