今日头条笔试,唯一写出的第四题
一定要吐槽一下第一题真是BT ,是输出格式有问题吗 用了好几种方法都是0
第四题倒是简单,就是输入格式真是坑爹,最后一分钟写完 没提交上😭😭😭
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
String s = sc.nextLine();
s = s.replaceAll(" ", "");
String st[] = s.split("");
//System.out.println(k);
//String a [] = {"1","2","3","5"};
fun(st,k-1);
}
public static void fun(String a[],int b){
int n=1,k = 1;
for(int i = a.length-1;i>0;i--){
n = n*i;
k = k*Integer.parseInt(a[i]);
}
int d [] = new int[n];
int c = 0;
for(int i = 0;i<a.length;i++){
for(int j = i+1;j<a.length;j++){
d[c] = (k*Integer.parseInt(a[i]))/Integer.parseInt(a[j]);
c++;
}
}
Arrays.sort(d);
int p = d[b];
for(int i = 2;i<=p;i++){
if(p%i==0&&k%i==0){
p = p/i;
k = k/i;
i = i-1;
}
}
System.out.println(p+" "+k);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
String s = sc.nextLine();
s = s.replaceAll(" ", "");
String st[] = s.split("");
//System.out.println(k);
//String a [] = {"1","2","3","5"};
fun(st,k-1);
}
public static void fun(String a[],int b){
int n=1,k = 1;
for(int i = a.length-1;i>0;i--){
n = n*i;
k = k*Integer.parseInt(a[i]);
}
int d [] = new int[n];
int c = 0;
for(int i = 0;i<a.length;i++){
for(int j = i+1;j<a.length;j++){
d[c] = (k*Integer.parseInt(a[i]))/Integer.parseInt(a[j]);
c++;
}
}
Arrays.sort(d);
int p = d[b];
for(int i = 2;i<=p;i++){
if(p%i==0&&k%i==0){
p = p/i;
k = k/i;
i = i-1;
}
}
System.out.println(p+" "+k);
}
}