360笔试————计算器格式输出一个数的素因子乘积形式

360笔试————计算器格式输出一个数的素因子乘积形式
全部评论
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { char[][] zero = { {' ','-',' '},{'|',' ','|'},{' ',' ',' '}, {'|',' ','|'},{' ','-',' '}} ; char[][] one = {{' ',' ',' '},{' ','|',' '},{' ',' ',' '}, {' ','|',' '},{' ',' ',' '} } ; char[][] two = {{' ','-',' '},{' ',' ','|'},{' ','-',' '}, {'|',' ',' '},{' ','-',' '} } ; char[][] three = {{' ','-',' '},{' ',' ','|'},{' ','-',' '}, {' ',' ','|'},{' ','-',' '} }; char[][] four = { {' ',' ',' '} ,{'|',' ','|'},{' ','-',' '}, {' ',' ','|'},{' ',' ',' '} }; char[][] five ={ {' ','-',' '},{'|',' ',' '},{' ','-',' '}, {' ',' ','|'},{' ','-',' '} }; char[][] six = {{' ','-',' '},{'|',' ',' '},{' ','-',' '}, {'|',' ','|'},{' ','-',' '} }; char[][] seven = {{' ','-',' '},{' ',' ','|'},{' ',' ',' '}, {' ',' ','|'},{' ',' ',' '} }; char[][] eight ={{' ','-',' '},{'|',' ','|'},{' ','-',' '}, {'|',' ','|'},{' ','-',' '} }; char[][] nine = {{' ','-',' '},{'|',' ','|'},{' ','-',' '}, {' ',' ','|'},{' ','-',' '} }; char[][] x = {{' ',' ',' '},{' ',' ',' '},{' ','*',' '}, {' ',' ',' '},{' ',' ',' '} }; char[][][] sum = { zero,one,two,three,four,five,six,seven,eight,nine,x }; Scanner cin = new Scanner(System.in); ArrayList<Integer> list = new ArrayList<Integer>() ; // long n = cin.nextLong() ; while(cin.hasNext()){ int number=cin.nextInt(); int i = 1; while (i < number) { if (number % i == 0 && i == 1){ number /=i; }else if (number % i == 0 && i != 1) { list.add(i) ; number /=i; continue; } i++; } list.add(i) ; for(int time_five = 0 ; time_five < 5 ; time_five ++){ for(int list_time = 0 ;list_time < list.size()-1 ; list_time ++){ int numbers = (Integer)list.get(list_time); System.out.print(sum[numbers][time_five]); System.out.print(sum[10][time_five]); } int numberss =(Integer) list.get(list.size()-1) ; System.out.print(sum[numberss][time_five]); System.out.println() ; } list.clear(); System.out.println() ; } } }
点赞 回复 分享
发布于 2015-09-15 23:37
顶。我的本地可以运行,依次输入一个数,然后输出结果。但是昨天考试的时候提交似乎要求一连输入一串数,然后再批量运行。您这通过了吗?
点赞 回复 分享
发布于 2015-09-16 08:46
import java.util.ArrayList; import java.util.Scanner; public class Main { // 定义输出数字 // 定义0-9 private static final String num0[] = new String[] { " - ", "| |", " ", "| |", " - " }; private static final String num1[] = new String[] { " ", " |", " ", " |", " " }; private static final String num2[] = new String[] { " - ", " |", " - ", "| ", " - " }; private static final String num3[] = new String[] { " - ", " |", " - ", " |", " - " }; private static final String num4[] = new String[] { " - ", "| |", " - ", " |", " " }; private static final String num5[] = new String[] { " - ", "| ", " - ", " |", " - " }; private static final String num6[] = new String[] { " - ", "| ", " - ", "| |", " - " }; private static final String num7[] = new String[] { " - ", " |", " ", " |", " " }; private static final String num8[] = new String[] { " - ", "| |", " - ", "| |", " - " }; private static final String num9[] = new String[] { " - ", "| |", " - ", " |", " - " }; // 定义操作符* private static final String num10[] = new String[] { " ", " ", "*", " ", " " }; // 整合 private static final String allNum[][] = { num0, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10 }; public static int[] dealLt10(int temp) { String target = "" + temp; int len = target.length(); int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = target.charAt(i) - 48; } return res; } public static ArrayList<Integer> getPrimeNumber(int num) { // 结果数组 ArrayList<Integer> result = new ArrayList<Integer>(); // 最小质数 开始 int starNumber = 2;// 定义最小的质数 // 判断1 if (num <= 1) { result.add(0); } else { // 在质数小于输入的数时,进行循环 while (starNumber <= num) { if (starNumber == num) {// 当质数等于输入的数时,直接输出 // 输出字符 // result.add(num); if (num >= 0 && num <= 9) result.add(num); else { int[] temp = dealLt10(num); for (int c = 0; c < temp.length; c++) { result.add(temp[c]); } } break; } else if (num % starNumber == 0) {// 当输入的数与质数的余数为0时,输出这个质数 // 输出字符 // result.add(starNumber); if (num >= 0 && num <= 9) result.add(starNumber); else { int[] temp = dealLt10(starNumber); for (int c = 0; c < temp.length; c++) { result.add(temp[c]); } } result.add(-1); num = num / starNumber;// 把剩下的结果赋给num } else {// 在余数不为0时,质数递增 starNumber++; } } } return result; } public static void printNumber(ArrayList<Integer> result) { // 循环输出 for (int n = 0; n < 5; n++) { for (int m = 0; m < result.si敏感词t temp = result.get(m); if (temp == -1) System.out.print(allNum[10][n]); else System.out.print(allNum[temp][n]); } System.out.println(""); } } public static void main(String[] args) { int num; Scanner cin = new Scanner(System.in); while (cin.hasNextInt()) { num = cin.nextInt(); // 获取素数数组 ArrayList<Integer> result = getPrimeNumber(num); // 打印数组 printNumber(result); } } } 给个参考,自己写的,没在线测试
点赞 回复 分享
发布于 2015-09-16 10:41
//线上AC了 import java.util.ArrayList; import java.util.Scanner; public class Main { public static final char[][] number_0={{' ','-',' '},{'|',' ','|'},{' ',' ',' '},{'|',' ','|'},{' ','-',' '}}; public static final char[][] number_1={{' ',' ',' '},{' ',' ','|'},{' ',' ',' '},{' ',' ','|'},{' ',' ',' '}};     public static final char[][] number_2={{' ','-',' '},{' ',' ','|'},{' ','-',' '},{'|',' ',' '},{' ','-',' '}};     public static final char[][] number_3={{' ','-',' '},{' ',' ','|'},{' ','-',' '},{' ',' ','|'},{' ','-',' '}};     public static final char[][] number_4={{' ',' ',' '},{'|',' ','|'},{' ','-',' '},{' ',' ','|'},{' ',' ',' '}};     public static final char[][] number_5={{' ','-',' '},{'|',' ',' '},{' ','-',' '},{' ',' ','|'},{' ','-',' '}};     public static final char[][] number_6={{' ','-',' '},{'|',' ',' '},{' ','-',' '},{'|',' ','|'},{' ','-',' '}};     public static final char[][] number_7={{' ','-',' '},{' ',' ','|'},{' ',' ',' '},{' ',' ','|'},{' ',' ',' '}};     public static final char[][] number_8={{' ','-',' '},{'|',' ','|'},{' ','-',' '},{'|',' ','|'},{' ','-',' '}};     public static final char[][] number_9={{' ','-',' '},{'|',' ','|'},{' ','-',' '},{' ',' ','|'},{' ','-',' '}}; public static void main(String[] args) { Scanner cin = new Scanner(System.in); //输入数据组数 while(cin.hasNext()){ //输入的数据 int n = cin.nextInt(); //需要打印的结果 ArrayList<Integer> result = new ArrayList<Integer>(); while(true){    if(n < 2) break;    boolean flag = false;    for(int j = 2; j <= n; j++){        if(n % j == 0){            result.add(j);            flag = true;            n = n / j;            break;        }    }    if(!flag) break; } printResult(result); if(cin.hasNext()) System.out.println(); } } public static void printResult(ArrayList<Integer> list){ ArrayList<ArrayList<Character>> result = new ArrayList<ArrayList<Character>>(); for(int i = 0; i < 5; i++){ result.add(new ArrayList<Character>()); } for(int i = 0; i< list.size();  i++){ int number = list.get(i); String StringInt= String.valueOf(number); for(int j = 0; j < StringInt.length();j++){ char fch=StringInt.charAt(j); //{' ','-',' '},{'|',' ','|'},{' ',' ',' '},{'|',' ','|'},{' ','-',' '} if(fch == '0'){ add(result,number_0); }else if(fch == '1'){ add(result,number_1); }else if(fch == '2'){ add(result,number_2); }else if(fch == '3'){ add(result,number_3); }else if(fch == '4'){ add(result,number_4); }else if(fch == '5'){ add(result,number_5); }else if(fch == '6'){ add(result,number_6); }else if(fch == '7'){ add(result,number_7); }else if(fch == '8'){ add(result,number_8); }else if(fch == '9'){ add(result,number_9); } } result.get(0).add(' '); result.get(1).add(' '); result.get(2).add('*'); result.get(3).add(' '); result.get(4).add(' '); } for(int i = 0; i < 5; i++){ result.get(i).remove(result.get(i).size() -1); for(Character c : result.get(i)){ System.out.print(c); } if(i != 4) System.out.println(); } } public static void add(ArrayList<ArrayList<Character>> result,char[][] number){ for(int i = 0; i < 5; i++){ result.get(i).add(number[i][0]); result.get(i).add(number[i][1]); result.get(i).add(number[i][2]); } } }
点赞 回复 分享
发布于 2015-09-17 12:04

相关推荐

kl_我是东山啊:《相关公司:阿里巴巴》
投递阿里巴巴等公司10个岗位
点赞 评论 收藏
分享
2024-12-27 23:45
已编辑
三江学院 Java
程序员牛肉:死局。学历+无实习+项目比较简单一点。基本就代表失业了。 尤其是项目,功能点实在是太假了。而且提问点也很少。第一个项目中的使用jwt和threadlocal也可以作为亮点写出来嘛?第二个项目中的“后端使用restful风格”,“前端采用vue.JS”,“使用redis”也可以作为亮点嘛? 项目实在是太简单了,基本就是1+1=2的水平。而你目标投递的肯定也是小厂,可小厂哪里有什么培养制度,由于成本的问题,人家更希望你来能直接干活,所以你投小厂也很难投。基本就是死局,也不一定非要走后端这条路。可以再学一学后端之后走测试或者前端。 除此之外,不要相信任何付费改简历的。你这份简历没有改的必要了,先沉淀沉淀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务