主观题:h0012.如果得到随机的字串,长度和字串中出现的字符表可定义,并将字串倒序显示。
如果得到随机的字串,长度和字串中出现的字符表可定义,并将字串倒序显示,如把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")}'
答案:[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")}'