拼多多7.22笔试题
第一题
package questions; import java.util.Scanner; public class Solution46 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int i=0; for(;i<num;i++) { if(4*(Math.pow(2, i)-1)>num) break; } int j=i-1; double cha = (double) (num-4*(Math.pow(2, j)-1)); int result = (int) (Math.ceil(cha/Math.pow(2, j))); if(result==1) System.out.println("Alice"); if(result==2) System.out.println("Bob"); if(result==3) System.out.println("Cathy"); if(result==4) System.out.println("Dave"); } }
第二题
package questions;
import java.util.Scanner;
public class Solution47 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int []sum =new int [N];
String [] str = new String[M];
for(int i=0;i<M;i++)
{
String s= sc.next();
str[i]=s;
}
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
sum[i]+=(int)str[j].charAt(i);
}
}
int min=sum[0];
int max=sum[0];
int flag =0;
for(int i=0;i<N;i++)
{
if(sum[i]<min)
{
min=sum[i];
flag=i;
}
}
int count =0;
for(int i=0;i<N;i++)
{
if(sum[i]==min)
count++;
}
if(count>1)
System.out.println(-1);
else
System.out.println(flag);
}
}
第三题
import java.util.Scanner;
public class Solution47 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int []sum =new int [N];
String [] str = new String[M];
for(int i=0;i<M;i++)
{
String s= sc.next();
str[i]=s;
}
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
sum[i]+=(int)str[j].charAt(i);
}
}
int min=sum[0];
int max=sum[0];
int flag =0;
for(int i=0;i<N;i++)
{
if(sum[i]<min)
{
min=sum[i];
flag=i;
}
}
int count =0;
for(int i=0;i<N;i++)
{
if(sum[i]==min)
count++;
}
if(count>1)
System.out.println(-1);
else
System.out.println(flag);
}
}
package questions;
import java.util.Arrays;
import java.util.Scanner;
public class Solution48 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String [] str = s.split(" ");
int [] arr = new int[str.length];
for(int i=0;i<str.length;i++)
{
arr[i]=Integer.parseInt(str[i]);
}
Arrays.sort(arr);
double sum =0.0;
int i=0;
int j=arr.length-1;
while(j>=i)
{
if(arr[j]>200)
{
sum+=1.0;
j--;
}
if(arr[i]+arr[j]<=300&&arr[i]+arr[j]>200)
{
sum+=1.0;
i++;
j--;
}
else if(arr[i]+arr[j]>300)
{
sum+=1.0;
j--;
}
else
{
sum+=1.0/3.0;
i++;
}
}
System.out.println((int)Math.ceil(sum));
}
}
#笔试题目##拼多多#import java.util.Arrays;
import java.util.Scanner;
public class Solution48 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String [] str = s.split(" ");
int [] arr = new int[str.length];
for(int i=0;i<str.length;i++)
{
arr[i]=Integer.parseInt(str[i]);
}
Arrays.sort(arr);
double sum =0.0;
int i=0;
int j=arr.length-1;
while(j>=i)
{
if(arr[j]>200)
{
sum+=1.0;
j--;
}
if(arr[i]+arr[j]<=300&&arr[i]+arr[j]>200)
{
sum+=1.0;
i++;
j--;
}
else if(arr[i]+arr[j]>300)
{
sum+=1.0;
j--;
}
else
{
sum+=1.0/3.0;
i++;
}
}
System.out.println((int)Math.ceil(sum));
}
}
第四题 不会