Board logo

标题: [技术讨论] 做题:数字黑洞一例(523066680版主出的) [打印本页]

作者: sxw    时间: 2011-10-18 21:39     标题: 做题:数字黑洞一例(523066680版主出的)

批版的601997526 已经写出来了,俺写个Perl版的:
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. while (1) {
  5. print "Type a number between 1000-9999:";
  6. chomp (my $num=<STDIN>);
  7. redo if $num !~ /^\d\d\d\d$/;
  8. redo if $num =~ /^(\d)\1\1\1$/;
  9. until ($num==6174) {
  10. my @big_to_small=sort {$b <=> $a } split //,$num;
  11. my @small_to_big=reverse @big_to_small;
  12. my $left=join "",@big_to_small;
  13. my $right=join "",@small_to_big;
  14. $num=scalar($left-$right);
  15. print "$left-$right=","$num\n";
  16. }
  17. print "-" x 15,"\n";
  18. }
复制代码

作者: 523066680    时间: 2011-10-20 11:07

前来支持~
作者: sxw    时间: 2011-10-20 11:14

回复 2# 523066680


    热烈欢迎,哈哈




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2