首页 > 编程知识 正文

华为sd考试答案,华为机试题可以上网搜吗

时间:2023-05-05 04:21:44 阅读:144758 作者:1863

在[编程|100点]字符串中找到连续最长的数字串

时间限制: 3秒

空间限制: 32768K

主题说明

请在字符串中找到最长的数字串,并返回该列的长度; 如果有相同长度的连续数字串,则返回最后一个连续数字串。

注:数字列只需要由数字组成,不需要顺序。 例如,数字串" 1234 "的长度短于数字串" 1359055 ",如果没有数字,则返回空字符串" "而不是NULL! (说明:无需考虑负数)

输入说明:

字符串输出记述:

连续的数字串是所有数字串中最长的长度

例1

输入

abcd12345ed125ss123058789

输出功率

123058789

9

# include iostream # includestringusingnamespacestd; int main () { string s; while(CINs ) { int len=0; int maxLen=0; int pos=-1; for(intI=0; i s.size (; I () if (s ) I )='0's )='9) ) Len; if({ maxLen=len ) ) Maxlen=Len; pos=i; } } else { len=0; }if(maxLen ) couts.substr ) pos-Maxlen1,Maxlen ) endl; cout maxLen endl; }返回0; }2.数[编程|200分]数的游戏

时间限制: 3秒

空间限制: 32768K

主题说明

100人围成一个圈,每个人都有代码,号码从1到100。 他们从1开始计数,报告m的人自动退出yxdz,下一个人从1开始计数,直到剩下的人数不到m。 最后剩下的人原来的号码是多少? 例如,输入M=3时,输出为“58,91”,输入M=4时,输出为“34、45、97”。

输入说明:

函数原型:

voidnumberoffgame(intm,char * output;

输入的m。 m是大于1小于100的整数。 输出说明:

输出output。 output已经分配了足够的内存空间,不需要单独分配。

m输入为1以下时,显示“ERROR! ”输出;

如果m输入为100以上,则显示“ERROR! ”输出;

否则,按照编号从小到大的顺序,用“,”分割输出编号字符串,输出字符串中的标点符号为半角字符。

例1

输入

3

输出功率

58,91

# include iostream # include string # include vector # include queue # include functional # includelistusingnamespacestd; int main () intn=100,m; while(CINm ) { listint linkedlist; for(intI=1; i=n; I )链接列表. push _ back (I; }if(m=1|||m=100 ) { cout 'ERROR!' endl; 继续; } listint : iterator ITER=linked list.begin (; while (链接列表. size (=m ) ) intd=m-1; wile(d---- ) { iter; if(ITER==Linkedlist.end () iter=linkedlist.begin ); } listint :3360迭代器temp=ITER; iter; if(ITER==Linkedlist.end () iter=linkedlist.begin ); linkedlist.Erase(temp ); (} iter=linkedlist.begin ); cout *iter; wile(ITER!=链接列表. end () ) cout )、(*iter; cout endl; }返回0; }3.[编程|300分]连接啤酒

时间限制: 3秒

空间限制: 32768K

主题说明

酒馆里有m个水龙头,客人们可以收啤酒。 每个水龙头每秒的出酒量相等,都是1。 现有的n名顾客已经准备好接收酒,他们接收第一瓶酒的顺序已经确定。 将这些顾客按接酒顺序从1号到n号,第I号顾客的接酒量设为w_i。 领酒时,1号到m号客人各占一个酒水龙头,同时打开水龙头领酒。 其中一位顾客j完成其酒量要求wj后,下一位排队等酒的顾客k马上开始接手j客的位置接受酒。 这个交替的过程瞬间完成,也没有浪费酒。 也就是说,j客在第x秒结束时收完酒,k客在第x 1秒立即开始收酒。 当前接酒人数低于m时,只有n’个水龙头供酒,其他m-n’个水龙头关闭。 现在拿出n个顾客的接酒量,按照上述规则,给所有顾客接酒结束需要几秒钟?

输入说明:

包括两行,第一行用空格分割的两个数n和m分别表示接受酒的人数和酒的头数,都是正整数。

第二行中的n个整数w_I(1=w_I=100 )表示每个顾客的酒量输出描述:

输入合法出口酒所需的总时间(秒)时。

注:请勿在最终提供的函数代码中打印输出与控制台无关的信息。

例1

输入

5 3

4 4 1 2 1

输出功率

4

# include iostream # include string # include vector # include queue # includefunctionalusingnamespacestd; int main ()/freopen (c : (用户(以太网(桌面) ) Huawei3.txt (,r ),stdin ); int n,m; while(cinnm ) { priority_queue int,vectorint,greaterint s; int w; for(intI=1; i=m; I ) s.push(0; for(intI=0; i n; I () { cin w; s.push(s.top ) ) w; s.pop (; }while(s.size )!=1) s.pop ); cout s.top () endl; }返回0; }

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