xx科技 开发 笔试
1 . 数位之积
给定n ,找到最小正整数m,使m的各位之乘积等于n,不存在输出-1 ;
test case :
36 ---> 49
首先m的位数一定要小,从9开始遍历,取n的因子,取到所有因子从小到大排序即可 ;
import java.util.* ;
class Solution {
/*
@param input:输入字符串序列
@return int:返回正确的结果
*/
public int func(String str) {
// Please fill this blank
int n = 0 ;
int ans = 0 ;
char[] ch = str.toCharArray() ;
for(char c : ch) n = n * 10 + (c-'0') ;
int[] a = new int[1001] ;
int idx = 0 ;
for(int i=9;i>=2;i--){
while(n%i==0){
n /= i ;
a[idx++] = i ;
}
}
if(n>1){
return -1 ;
}
int[] b = new int[idx] ;
for(int i=0;i<idx;i++){
b[i] = a[i] ;
}
Arrays.sort(b) ;
for(int x : b) ans = ans * 10 + x ;
return ans ;
}
}
2.礼盒
()表示一个礼品盒,0表示奖品,求最少才开礼品盒数量 ;
test case :
(((0))) ----> 3
左右求最小数量即可 ;
import java.util.* ;
class Solution {
/*
@param input:输入字符串序列
@return int:返回正确的结果
*/
public int func(String str) {
// Please fill this blank
char[] ch = str.toCharArray() ;
int ans = 0 , res = 0 ;
int n = ch.length ;
int idx = 0 ;
for(int i=0;i<n;i++) if(ch[i]=='0') {
idx = i ;
break ;
}
for(int i=0;i<idx;i++){
if(ch[i]=='(') ans ++ ;
if(ch[i]==')') ans -- ;
}
for(int i=n-1;i>idx;i--){
if(ch[i]==')') res ++ ;
if(ch[i]=='(') res -- ;
}
int yss = Math.min(ans,res) ;
return yss ;
}
}
3.做手机
假设第一天量产1台,接下来2天(即第二、三天)每天量产2件,接下来3天(即第四五、六天)每天量产3件......以此类推,请编程计算出第n天总共可以量产的手机数量。
模拟即可 :
import java.util.* ;
class Solution {
/*
@param input:输入字符串序列
@return int:返回正确的结果
*/
public int func(String str) {
// Please fill this blank
char[] s = str.toCharArray() ;
int n = 0 ;
for(char c : s) n = n * 10 + (c-'0') ;
int ans = 0 ;
int t = 1 ,d = 1 ,nd = 1;
while(d<=n){
for(int day=0;day<nd&&d<=n;++day){
ans+=nd;
d++ ;
}
nd++ ;
}
return ans ;
}
}
#你都收到了哪些公司的感谢信?##我的实习求职记录##软件开发笔面经#秋招joker 文章被收录于专栏
记录秋招...

查看13道真题和解析