#携程笔试#
题目1
题目1
时间限制: 3000MS
        内存限制: 589824KB
        题目描述:
        假设在一条无限长的道路上盖房子,第一个月在某个点盖一个红房子,之后每个月,都会在上一次盖的新房子的左边盖一个绿房子,
        右边盖一个红房子。(假设两个房子之间的空间无限大,可以一直在中间盖房子)
        用字符'R'表示红房子,用字符'G'表示绿房子。
        输入一个n(1≤n≤12),表示过了n个月,打印出当前道路上房子从左到右的排列。
        要求:
        1.    当输入非数字,输出:N

        2.    当输入数字超出限制时,输出O

        样例:

        输入1

        输出 R

        输入2

        输出 GRR

        输入3

        输出 GGRRGRR

        输入5

        输出 GGRGGRRGGGRRGRRRGGRGGRRRGGRRGRR

题目2
 时间限制: 3000MS
内存限制: 589824KB
题目描述:
一般在代码Code Review或者持续集成过程中,一次代码提交会触发代码的重新编译及正在Review过程的Pull Request的Approval重置,为了加快编译或者只重置受影响的Pull Reqeust,都会进行代码包依赖分析,找出受影响的代码包(package)。我们使用正整数表示包,对给定的被修改的包,求出所有受影响的包(去重)所代表数字的和,若无受影响的包,则和返回-1。注意,直接依赖及间接依赖的包被修改,当前包均被定义为受影响。

输入描述
第一行为整数,代表被修改的包。 第二行开始的后续行都是数组,代表数组的第一个元素依赖后续的元素,注意数组元素可能只有1个,代表该包无依赖。 如输入样例的含义为被修改的包是4,包1依赖2, 包3依赖4、5、6,  包2依赖3,  包6依赖4、2, 包8依赖9,包10无依赖。

输出描述
所有受影响的包去重后为1、2、3、6,所以其和为12.

样例输入
4
1,2
3,4,5,6
2,3
6,4,2
8,9
10
样例输出
12
全部评论
我的题和你一样
1 回复
分享
发布于 2021-04-15 21:03
第一道题ac了90,还有10死活ac不出来 第二道ac了85,也是调不出来了 第一题代码: public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str=br.readLine(); for(int i=0;i<str.length();i++) { if(!Character.isDigit(str.charAt(i))) { System.out.println("N"); return; } } int n=Integer.parseInt(str); if(n<1||n>12) { System.out.println("O"); return; } StringBuffer result=new StringBuffer("R"); int j=0; int length=result.length(); for(int i=0;i<n-1;i++) { length=result.length()*2+1; for(j=0;j<length;j+=2) { result.insert(j,"G"); j+=2; result.insert(j,"R"); } } System.out.println(result); } } 第二题代码 public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int change=Integer.parseInt(br.readLine()); String str=null; HashMap<Integer,ArrayList<Integer>> record= new HashMap<Integer,ArrayList<Integer>>(); HashSet<Integer> settle=new HashSet<Integer>(); settle.add(change); int result=0; while((str=br.readLine())!=null) { if(str.equals("mmp")) { break; } String[] temp=str.split(","); if(temp.length==1) { continue; } int n=Integer.parseInt(temp[0]); for(int i=1;i<temp.length;i++) { int a=Integer.parseInt(temp[i]); if(record.containsKey(a)) { ArrayList<Integer> temp1=record.get(a); temp1.add(n); record.put(a,temp1); continue; } else { ArrayList<Integer> temp1=new ArrayList<Integer>(); temp1.add(n); record.put(a,temp1); } } } ArrayList<Integer> solve=new ArrayList<Integer>(); solve.add(change); int arr=0; while(arr!=solve.size()) { ArrayList<Integer> temp=record.get(solve.get(arr++)); if(temp==null) { continue; } for(int i=0;i<temp.size();i++) { if(!settle.contains(temp.get(i))) { result+=temp.get(i); settle.add(temp.get(i)); solve.add(temp.get(i)); } } } System.out.println(result); } } 题都不难,很快作出来了,但是不知道哪些边界条件卡死我了😓
点赞 回复
分享
发布于 2021-04-15 20:49
联想
校招火热招聘中
官网直投
感觉很噶
点赞 回复
分享
发布于 2021-04-15 20:49
第二道同85,不知道啥情况
点赞 回复
分享
发布于 2021-04-15 20:58
第一题可能是负数,判断为符号输出是“O” 不是“N”
点赞 回复
分享
发布于 2021-04-15 21:08
第二道题85的话可能是因为没有判断环的情况。加个判环 85% -> 100%
点赞 回复
分享
发布于 2021-04-15 21:10
第一道题90是因为数字的开头可能是+-号,需要特判一下。
点赞 回复
分享
发布于 2021-04-15 21:12
携程是不招.NET了吗 连C#语言都没 用python磨出来了😓
点赞 回复
分享
发布于 2021-04-15 21:18

相关推荐

4 收藏 评论
分享
牛客网
牛客企业服务