-->
当前位置:首页 > 题库 > 正文内容

主观题:h0012.如果得到随机的字串,长度和字串中出现的字符表可定义,并将字串倒序显示。

Luz3年前 (2022-10-05)题库239
如果得到随机的字串,长度和字串中出现的字符表可定义,并将字串倒序显示,如把0123456789 作为基准的字串字符表,产生一个6位的字串642031,打印出的字串为130246,可使用bash/perl/php/c 任意一种.





答案:[root@localhost ~]# awk -v count=6 'BEGIN

{srand();str="0123456789";len=length(str);for(i=count;i>0;i--)

marry[i]=substr(str,int(rand()*len),1);for(i=count;i>0;i--)

printf("%c",marry[i]);printf("\n");for

(i=0;i<=count;i++) printf("%c",marry[i]);printf("\n")}'

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。