首页 > 编程知识 正文

华为sd流程考试题库,华为面试题及答案

时间:2023-05-05 18:55:15 阅读:120198 作者:3043

今天,我请同学看了华为的钢笔问题。 主题如下。

举办8个小时的派对。 时间段是12:00点到20:00点,让来访客人提前填写到达时间和出发时间。 为了掌握聚会期间的座位数,需要估计各时间的最大客人数。

1 .到达和出发的时间,正点计算,作为整数输入。 例如,“12,18”表示客人到达时间为12点后13点前,出发时间为17点后18点前。

2 .要按时段统计客流量,[ 12,13 ]、[ 13,14 ]…. [ 19,20 ]共需统计8个时段的最大客流量。

3 .邀请的客人最多100人。

假设输入:

12、1516、1712、20程序要求的输出结果如下。

[ 12,13 ] :2 [ 13,14 ] :2 [ 14,15 ] :2 [ 15,16 ] :1 [ 16,17 ] 33602 [ 17,18,19 ] 3:1 [ 18,16 ]

import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Hashtable; import java.util.List; 公共类测试{ publicstaticliststringlist=newarrayliststring (; publicstaticvoidmain (string [ ] args ) string [ ] str={ ' 12,15 '、' 16,17 '、' 12,20 ' }; for(intI=0; i str.length; I ) ) reset(str[I]; } HashtableString,Integer wordCount=wordcount (; liststringnewlist=newarrayliststring (; for (字符串密钥: word count (.keyset ) ) newlist.add ) ([ ' key ' ] ' : ' word count.get ) ) key ); //collections.sort (新列表,新比较器) (公共int比较器) Object o2,Object o2 ) stringstr1=(字符串) ompare ) if (str1.比较到Ignore case (str2)0) {返回- 1; }返回1; }; ); //输出结果for (inti=0; i newlist.size (; I ) system.out.println (new list.get (I ); }//字符串组合起来创建格式,类似于16,17 staticvoidreset (stringstr ) string ) (aa=str.split )、()、() ) )。 int inter=integer.parseint (aa [1]-integer.parseint ) aa[0]; for(intI=0; i inter; I ) int new string=integer.parseint (aa [0] ) I; list.add(newstring ',') newString 1); }//统计次数static HashtableString,Integer wordcount () { HashtableString,integer word count=newhashtablestring,integer ) ) for(intI=0; i list.size (; I ) (stringstr=list.get ) I; if (! wordcount.containskey(str ) ) wordcount.put ) str,Integer.valueOf(1) )1); }else{wordcount.put(str,integer.valueof ) word count.get (str ).intValue () )1); } }返回窗口计数; }对于没有学习过数据结构和算法的人,先用这种方法处理。 处理逻辑首先将" 12、15 "这样指定字符处理为必要的字符串,例如12、13; 十三、十四; 十四十五。 接下来,在各制作字符串处理完成后,使用map集合来计数各字符串(例如12、13 )出现的总次数。 最后,由于map的key顺序不正确,使用Collections.sort进行排序,最终得到输出结果。

相应的python代码为https://blog.csdn.net/tsz upup/article/details/81739630

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。