40选择题,2道编程题。
1. 第一道编程很简单,根据研究生的四门课入学成绩判断,Fail或Gongfei,Zifei。
import java.util.Scanner;
/**
* Created by aifei on 15/9/15.
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-->0){
int []score = new int[4];
for(int i = 0;i<4;i++){
score[i] = sc.nextInt();
}
int sum = score[0] + score[1] + score[2] + score[3];
if(!isFail(score,sum)){
System.out.println("Fail");
}else{
if(sum>=310 && sum<=349){
System.out.println("Zifei");
}else{
System.out.println("Gongfei");
}
}
}
}
private static boolean isFail(int[] score,int sum) {
if(score[0]>=60 && score[1]>=60 && score[2]>=90 && score[3]>=90 && sum>=310){
return true;
}else {
return false;
}
}
}
2. 素因子分解,并以可视化数字输出素因子。
import java.util.ArrayList;
import java.util.Scanner;
/**
* Created by on 15/9/15.
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
ArrayList<Integer> list = new ArrayList<Integer>();
int key = 1;
while(n > 1){
for(int i=2; i<=n;i++){
if(n%i==0){
key = i;
list.add(key);
break;
}
}
n = n/key;
}
for(int i=0; i<list.size();i++){
if(i!=list.size()-1){
visualOutPut(list.get(i));
System.out.print("*");
}else{
visualOutPut(list.get(i));
}
}
}
}
private static void visualOutPut(int num) {
String str = String.valueOf(num);
for(int i=0; i<str.length();i++){
char ch = str.charAt(i);
visualDigit(ch);
}
}
private static void visualDigit(char ch) {
switch (ch){
case '0':
System.out.println(" "+'-');
System.out.print("|");
System.out.println(" "+"|");
System.out.println(" "+'-');
System.out.print("|");
System.out.println(" "+"|");
System.out.print(" "+'-');
break;
case '1':
System.out.println("|");
System.out.println('|');
break;
case '2':
System.out.println(" "+'-');
System.out.println(" "+"|");
System.out.println(" "+'-');
System.out.println('|');
System.out.println(" "+'-');
break;
case '5':
System.out.println(" "+'-');
System.out.println("|");
System.out.println(" "+'-');
System.out.println(" "+'|');
System.out.print(" "+'-');
break;
}
}
}