엔지니어 필기시험 문제
8864 단어 인터넷 회사 필기시험 문제
제목1:
문제 설명
정수, 음수, 0을 포함하는 무질서한 수조를 정하고 그 중에서 3개의 수의 곱셈을 찾아내 곱셈이 가장 크고 시간 복잡도를 요구한다. O(n), 공간 복잡도: O(1)
코드 전시
package com.pdd;
import java.util.Scanner;
public class Demo1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long [] arr=new long[n];
//
for(int i=0;i// ,
System.out.println(getMaxMul(arr));
}
private static long getMaxMul(long[] arr) {
int n=arr.length;
// max1,max2,max3 min1,min2
long max1=0;
long max2=0;
long max3=0;
long min1=0;
long min2=0;
for(int i=0;iif (arr[i]>max1) {
max3=max2;
max2=max1;
max1=arr[i];
}else if (arr[i]>max2) {
max3=max2;
max2=arr[i];
}else if (arr[i]>max3) {
max3=arr[i];
}
if (arr[i]else if (arr[i]return (max1*max2*max3)>(max1*min1*min2)?(max1*max2*max3):(max1*min1*min2);
}
}
제목 2
제목 설명
두 개의 문자열로 표시된 매우 큰 정수가 있는데, 그들의 곱셈을 산출하는 것도 문자열로 표시한다.시스템 자체 정수 유형을 사용할 수 없습니다
코드 전시
package com.pdd;
import java.util.Scanner;
public class Demo2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str1 = sc.next();
String str2 = sc.next();
String res;
if (str1 == null || str2 == null) {
res=null;
}
if (str1.charAt(0)=='0'||str2.charAt(0)=='0') {
res=""+'0';
}
res= multiply(str1,str2);
System.out.println(res);
}
private static String multiply(String str1, String str2) {
//1.
String num1=new StringBuffer(str1).reverse().toString();
String num2=new StringBuffer(str2).reverse().toString();
int n1Length=num1.length();
int n2Length=num2.length();
//2. , n1Length+n2Length
int [] arr=new int [n1Length+n2Length];
for(int i=0;ifor(int j=0;j'0')*(num2.charAt(j)-'0');
}
}
StringBuffer sBuffer=new StringBuffer();
for(int i=0;iint curBit=arr[i]%10;
int postCur=arr[i]/10;
if (i+11]+=postCur;
}
sBuffer.insert(i, curBit);
}
if (sBuffer.reverse().charAt(0)=='0') {
sBuffer.deleteCharAt(0);
}
return sBuffer.toString();
}
}
제목 3
문제 설명
어린이날에 선생님은 맛있는 초콜릿을 많이 가지고 유치원에 가셨다.모든 초콜릿 j의 무게는 w[j]이다. 모든 어린이 i에게 그가 나누어 준 초콜릿의 크기가 h[i](즉 w[j]>=h[i])에 이르러서야 그는 프로그램에 출연할 수 있다.선생님의 목표는 초콜릿을 아이들에게 나누어 가장 많은 아이들이 무대에 올라 공연하도록 하는 것이다.모든 w[i]>0은 초콜릿을 한 아이에게 나누어 주거나 여러 아이에게 나누어 줄 수 없습니다.
코드 전시
package com.pdd;
import java.util.Arrays;
import java.util.Scanner;
public class Demo3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int childNum = sc.nextInt();
int arrChild[] = new int[childNum];
for (int i = 0; i < childNum; i++) {
arrChild[i] = sc.nextInt();
}
int teacNum = sc.nextInt();
int arrTeac[] = new int[teacNum];
for (int i = 0; i < teacNum; i++) {
arrTeac[i] = sc.nextInt();
}
//
Arrays.sort(arrChild);
Arrays.sort(arrTeac);
// , 1
int j=0;//
int count=0;//
for(int i=0;iif (j//
count++;
j++;
}
}
System.out.println(count);
}
}