学习是一种行为反射,不是为了晓得些知识,要切记体察,代入自己,要事上琢磨,落实行动,这就是知行合一,否则读书也是一种玩物丧志|

yfwei

园龄:4年粉丝:2关注:2

2022年携程春招实习笔试经验~

在3月10日晚7:00 - 9:00期间参加了携程的笔试考试,这也是第一次参加这种类型的笔试,所以在这总结一下经验吧,之后可以按照这个经验再积极准备别的厂的面试。

个人面试感觉应该是无了,就是不知道携程有没有感谢信,先等一手

首先题型上:往年携程是20 + 3的模式(20道选择题,3道编程题),今年改成了4道编程题,限时两个小时。

第一道是一个数组的规划问题,要求是运算符号两边要格式化,改成只有一个空格的格式化输出模式,用例如下所示:

用例1:dasds < sadasda
用例2: w < v
用例3: fsfsdfsdf> sadas

第二道题是一个不算很难的数组相乘问题,但是我考虑的过于麻烦😂,倒是在这个题目上面花费了相当多的时间,大概意思是: 一个孩子,上课没有听课,因此他理解的乘法是这样的

1 2 3

3 2 1

——

1 2 3

2 4 6

3 6 9

——

7 3 8

然后要求的输入用例为:

3

123 321

111

100 21

这个题目的解法还算是比较简单,只要将一个数字分离开来,比如将321分成arrays[0] = 3
arrays[1] = 2 arrays[2] = 1

然后依次与第一个操作数相乘,再相加到一起即可完成要求:


第三题不记得了,哈哈哈,因为属实没啥思路,就直接跳过了~


然后第四题的话是一个回文数的问题,这个题因为卡在了最后的时限,所以导致没能提交成功,(应该是系统卡了,我在本地IDE上运行速度还是挺快的),因此直接将答案贴在这里,感兴趣大家可以去了解一下~

import java.util.Scanner;
public class Question4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String[] strings = str.split(" ");
int a = Integer.parseInt(strings[0]);
int b = Integer.parseInt(strings[1]);
str = scanner.nextLine();
strings = str.split(" ");
int year = Integer.parseInt(strings[0]);
int mounth = Integer.parseInt(strings[1]);
int day = Integer.parseInt(strings[2]);
int result = combinData(year,mounth,day);
while(isAimedNumber(result) != true){
day = day + 1;
if(day > b){
mounth++;
day = 1;
}
if(mounth > a){
year++;
mounth = 1;
}
result = combinData(year,mounth,day);
}
int tempA = result;
int gridB = 1;
for(int i = 0 ; i < highestNum(mounth) + highestNum(day) ; i++){
tempA = tempA / 10;
gridB = gridB * 10;
}
year = tempA;
int tempB = result;
tempB = tempB % gridB;
tempB /= 10;
mounth = tempB;
day = result % 10;
System.out.println(year + " " + mounth + " " + day);
}
//把年月日组合到一起
private static int combinData(int year, int mounth, int day){
int result = 0;
for(int i = 0 ; i < highestNum(mounth) + highestNum(day) ; i++){
year = year * 10;
}
result = result + year;
for(int i = 0 ; i < highestNum(day) ; i++){
mounth = mounth * 10;
}
result = result + mounth + day;
return result;
}
//把年月日拆分开
//计算数字的最高位
private static int highestNum(int a){
int result = 0;
while(a / 10 > 0){
result++;
a = a / 10;
}
return result + 1;
}
//判断该数字是否为回文数字
private static boolean isAimedNumber(int temp){
if(temp < 0 || (temp % 10 == 0 && temp!= 0)){
return false;
}
int revertedNumber = 0;
while(temp > revertedNumber){
revertedNumber = revertedNumber * 10 + temp % 10;
temp /= 10;
}
return temp == revertedNumber || temp == revertedNumber / 10;
}
}

本文作者:yfwei's blog

本文链接:https://www.cnblogs.com/yfwei/p/15991417.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   yfwei  阅读(245)  评论(0编辑  收藏  举报
(评论功能已被禁用)
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示