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,准备下一行录入 } } } }
-
1
《java辅导》:学打表,练习打表,....
import java.util.Scanner; public class Main { public static void main(String[] args) { String[][] str = {{" _ ","| |","|_|"}, {" "," |"," |"}, {" _ "," _|","|_ "}, {" _ "," _|"," _|"}, {" ","|_|"," |"}, {" _ ","|_ "," _|"}, {" _ ","|_ ","|_|"}, {" _ "," |"," |"}, {" _ ","|_|","|_|"}, {" _ ","|_|"," _|"}}; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String s = sc.nextLine(); char[] chs = s.toCharArray(); for (int i = 0; i < 3; i++) { for (char ch: chs){ if(ch >= '0' && ch<= '9') { System.out.print(str[ch - '0'][i]); } } System.out.println(); } System.out.println(); } } }
-
0
switch分行输出,暴力解
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] arr = new int[4]; while(sc.hasNextInt()){ arr[0] = sc.nextInt(); arr[1] = sc.nextInt(); arr[2] = sc.nextInt(); arr[3] = sc.nextInt(); for(int i = 0;i < 4;i++){ if(arr[i] == 1 || arr[i] == 4){ System.out.print(" "); }else{ System.out.print(" _ "); } } System.out.println(); for(int i = 0;i < 4;i++){ switch (arr[i]){ case 1: case 7: System.out.print(" |"); break; case 2: case 3: System.out.print(" _|"); break; case 4: case 8: case 9: System.out.print("|_|"); break; case 5: case 6: System.out.print("|_ "); break; case 0: System.out.print("| |"); break; } } System.out.println(); for(int i = 0;i < 4;i++){ switch (arr[i]){ case 1: case 4: case 7: System.out.print(" |"); break; case 2: System.out.print("|_ "); break; case 3: case 5: case 9: System.out.print(" _|"); break; case 6: case 8: case 0: System.out.print("|_|"); break; } } System.out.println(); } } }
- 1
信息
- ID
- 3
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 27
- 已通过
- 4
- 上传者