一、15个单选、5个多选
二、3个编程
//1、输出第N个丑数
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int two = 0;
int three =0;
int five = 0;
ArrayList<Integer> ugly = new ArrayList<> ();
ugly.add(1);
for(int i = 0; i < a-1; i++ ){
while(true){
if(ugly.get(two) * 2 > ugly.get(ugly.size()-1)){
break;
}
two++;
}
while(true){
if(ugly.get(three) * 3 > ugly.get(ugly.size()-1)){
break;
}
three++;
}
while(true){
if(ugly.get(five) * 5 > ugly.get(ugly.size()-1)){
break;
}
five++;
}
int m = Math.min(ugly.get(two)*2,ugly.get(three)*3);
int n = Math.min(m,ugly.get(five)*5);
ugly.add(n);
}
System.out.println(ugly.get(a-1));
}
}
//2 a、b、c、d为0-9的正整数,abcd+bcda=8888,输出满足要求的所有a、b、c、d
输出格式为 a1 b1 c1 d1
a2 b2 c2 d2
………………
public class Main {
public static void main(String[] args) {
int a,b,c,d;
for(int i =0; i < 8888; i++ ){
a = i/1000;
b = (i-a*1000)/100;
c = (i-a*1000-b*100)/10;
d = i-a*1000-b*100-c*10;
if((i+b*1000+c*100+d*10+a) == 8888){
System.out.println(a+" "+b+" "+c+" "+d);
}
}
}
}
//3求不相邻的最大和
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
String s[] = str.split(",");
int len = s.length;
int [] num = new int[len];
for(int i = 0; i < len; i++){
num [i]= Integer.parseInt(s[i]);
}
int [] sum = new int[len+1];
sum[0] = 0;
sum [1] = num[0];
for(int i =2; i <=len; i++){
sum[i] = Math.max(sum[i-1],sum[i-2]+num[i-1]);
}
System.out.println(sum[len]);
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int two = 0;
int three =0;
int five = 0;
ArrayList<Integer> ugly = new ArrayList<> ();
ugly.add(1);
for(int i = 0; i < a-1; i++ ){
while(true){
if(ugly.get(two) * 2 > ugly.get(ugly.size()-1)){
break;
}
two++;
}
while(true){
if(ugly.get(three) * 3 > ugly.get(ugly.size()-1)){
break;
}
three++;
}
while(true){
if(ugly.get(five) * 5 > ugly.get(ugly.size()-1)){
break;
}
five++;
}
int m = Math.min(ugly.get(two)*2,ugly.get(three)*3);
int n = Math.min(m,ugly.get(five)*5);
ugly.add(n);
}
System.out.println(ugly.get(a-1));
}
}
//2 a、b、c、d为0-9的正整数,abcd+bcda=8888,输出满足要求的所有a、b、c、d
输出格式为 a1 b1 c1 d1
a2 b2 c2 d2
………………
public class Main {
public static void main(String[] args) {
int a,b,c,d;
for(int i =0; i < 8888; i++ ){
a = i/1000;
b = (i-a*1000)/100;
c = (i-a*1000-b*100)/10;
d = i-a*1000-b*100-c*10;
if((i+b*1000+c*100+d*10+a) == 8888){
System.out.println(a+" "+b+" "+c+" "+d);
}
}
}
}
//3求不相邻的最大和
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
String s[] = str.split(",");
int len = s.length;
int [] num = new int[len];
for(int i = 0; i < len; i++){
num [i]= Integer.parseInt(s[i]);
}
int [] sum = new int[len+1];
sum[0] = 0;
sum [1] = num[0];
for(int i =2; i <=len; i++){
sum[i] = Math.max(sum[i-1],sum[i-2]+num[i-1]);
}
System.out.println(sum[len]);
}
}
全部评论
(1) 回帖