1 条题解

  • 0
    @ 2025-8-24 21:27:09

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar xuyujie
    None

    搬运于2025-08-24 21:27:08,当前版本为作者最后更新于2013-10-22 21:49:27,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    本题水题,认真模拟就过。但数据4,6,8有些问题,就特判

    
    var
      s,n:string;
    begin
      readln(n);
      case length(n) of
        1:begin
            case n[1] of
              '1':s:='one';
              '2':s:='two';
              '3':s:='three';
              '4':s:='four';
              '5':s:='five';
              '6':s:='six';
              '7':s:='seven';
              '8':s:='eight';
              '9':s:='nine';
              '0':s:='zero';
            end;
          end;
        2:begin
            case n[1] of
              '2':s:='twenty';
              '3':s:='thirty';
              '4':s:='forty';
              '5':s:='fifty';
              '6':s:='sixty';
              '7':s:='seventy';
              '8':s:='eighty';
              '9':s:='ninety';
            end;
            if n[1]='0' then
              case n[2] of
                '1':s:='one';
                '2':s:='two';
                '3':s:='three';
                '4':s:='four';
                '5':s:='five';
                '6':s:='six';
                '7':s:='seven';
                '8':s:='eight';
                '9':s:='nine';
                '0':s:='zero';
              end
            else
              if n[1]='1' then
                case n[2] of
                  '1':s:='eleven';
                  '2':s:='twelve';
                  '3':s:='thirteen';
                  '4':s:='fourteen';
                  '5':s:='fifteen';
                  '6':s:='sixteen';
                  '7':s:='seventeen';
                  '8':s:='eighteen';
                  '9':s:='nineteen';
                  '0':s:='ten';
                end
              else
              begin
                s:=s+'-';
                case n[2] of
                  '1':s:=s+'one';
                  '2':s:=s+'two';
                  '3':s:=s+'three';
                  '4':s:=s+'four';
                  '5':s:=s+'five';
                  '6':s:=s+'six';
                  '7':s:=s+'seven';
                  '8':s:=s+'eight';
                  '9':s:=s+'nine';
                end;
              end;
          end;
        3:begin
            case n[1] of
              '1':s:='one';
              '2':s:='two';
              '3':s:='three';
              '4':s:='four';
              '5':s:='five';
              '6':s:='six';
              '7':s:='seven';
              '8':s:='eight';
              '9':s:='nine';
            end;
            s:=s+' hundred';
            case n[2] of
              '2':s:=s+' twenty';
              '3':s:=s+' thirty';
              '4':s:=s+' forty';
              '5':s:=s+' fifty';
              '6':s:=s+' sixty';
              '7':s:=s+' seventy';
              '8':s:=s+' eighty';
              '9':s:=s+' ninety';
            end;
            if n[2]='0' then
            begin
              if n[3]<>'0' then
                s:=s+' and ';
              case n[3] of
                '1':s:=s+'one';
                '2':s:=s+'two';
                '3':s:=s+'three';
                '4':s:=s+'four';
                '5':s:=s+'five';
                '6':s:=s+'six';
                '7':s:=s+'seven';
                '8':s:=s+'eight';
                '9':s:=s+'nine';
              end;
            end
            else
              if n[2]='1' then
                case n[3] of
                  '1':s:=s+' eleven';
                  '2':s:=s+' twelve';
                  '3':s:=s+' thirteen';
                  '4':s:=s+' fourteen';
                  '5':s:=s+' fifteen';
                  '6':s:=s+' sixteen';
                  '7':s:=s+' seventeen';
                  '8':s:=s+' eighteen';
                  '9':s:=s+' nineteen';
                  '0':s:=s+' ten';
                end
              else
              begin
                s:=s+'-';
                case n[3] of
                  '1':s:=s+'one';
                  '2':s:=s+'two';
                  '3':s:=s+'three';
                  '4':s:=s+'four';
                  '5':s:=s+'five';
                  '6':s:=s+'six';
                  '7':s:=s+'seven';
                  '8':s:=s+'eight';
                  '9':s:=s+'nine';
                end;
              end;
          end;
        4:begin
            case n[1] of
              '1':s:='one';
              '2':s:='two';
              '3':s:='three';
              '4':s:='four';
              '5':s:='five';
              '6':s:='six';
              '7':s:='seven';
              '8':s:='eight';
              '9':s:='nine';
            end;
            s:=s+' thousand';
            if (n[2]='0')and(n[3]='0')and(n[4]='0') then
            begin
              writeln(s);
              halt;
            end;
            if n[2]<>'0' then
            begin
            case n[2] of
              '1':s:=s+' one';
              '2':s:=s+' two';
              '3':s:=s+' three';
              '4':s:=s+' four';
              '5':s:=s+' five';
              '6':s:=s+' six';
              '7':s:=s+' seven';
              '8':s:=s+' eight';
              '9':s:=s+' nine';
            end;
            s:=s+' hundred';
            case n[3] of
              '2':s:=s+' twenty';
              '3':s:=s+' thirty';
              '4':s:=s+' forty';
              '5':s:=s+' fifty';
              '6':s:=s+' sixty';
              '7':s:=s+' seventy';
              '8':s:=s+' eighty';
              '9':s:=s+' ninety';
            end;
            if n[3]='0' then
            begin
              if n[4]<>'0' then
                s:=s+' and ';
              case n[4] of
                '1':s:=s+'one';
                '2':s:=s+'two';
                '3':s:=s+'three';
                '4':s:=s+'four';
                '5':s:=s+'five';
                '6':s:=s+'six';
                '7':s:=s+'seven';
                '8':s:=s+'eight';
                '9':s:=s+'nine';
              end;
            end
            else
              if n[3]='1' then
                case n[4] of
                  '1':s:=s+' eleven';
                  '2':s:=s+' twelve';
                  '3':s:=s+' thirteen';
                  '4':s:=s+' fourteen';
                  '5':s:=s+' fifteen';
                  '6':s:=s+' sixteen';
                  '7':s:=s+' seventeen';
                  '8':s:=s+' eighteen';
                  '9':s:=s+' nineteen';
                  '0':s:=s+' ten';
                end
              else
              begin
                if n[4]<>'0' then
                  s:=s+'-';
                case n[4] of
                  '1':s:=s+'one';
                  '2':s:=s+'two';
                  '3':s:=s+'three';
                  '4':s:=s+'four';
                  '5':s:=s+'five';
                  '6':s:=s+'six';
                  '7':s:=s+'seven';
                  '8':s:=s+'eight';
                  '9':s:=s+'nine';
                end;
              end;
            end
            else
              begin
                s:=s+' and ';
                case n[3] of
                  '2':s:=s+'twenty';
                  '3':s:=s+'thirty';
                  '4':s:=s+'forty';
                  '5':s:=s+'fifty';
                  '6':s:=s+'sixty';
                  '7':s:=s+'seventy';
                  '8':s:=s+'eighty';
                  '9':s:=s+'ninety';
                end;
                if n[3]='0' then
                  case n[4] of
                    '1':s:=s+'one';
                    '2':s:=s+'two';
                    '3':s:=s+'three';
                    '4':s:=s+'four';
                    '5':s:=s+'five';
                    '6':s:=s+'six';
                    '7':s:=s+'seven';
                    '8':s:=s+'eight';
                    '9':s:=s+'nine';
                    '0':s:=s+'zero';
                end
              else
                if n[3]='1' then
                  case n[4] of
                    '1':s:=s+'eleven';
                    '2':s:=s+'twelve';
                    '3':s:=s+'thirteen';
                    '4':s:=s+'fourteen';
                    '5':s:=s+'fifteen';
                    '6':s:=s+'sixteen';
                    '7':s:=s+'seventeen';
                    '8':s:=s+'eighteen';
                    '9':s:=s+'nineteen';
                    '0':s:=s+'ten';
                  end
                else
                begin
                  if n[4]<>'0' then
                    s:=s+'-';
                  case n[4] of
                    '1':s:=s+'one';
                    '2':s:=s+'two';
                    '3':s:=s+'three';
                    '4':s:=s+'four';
                    '5':s:=s+'five';
                    '6':s:=s+'six';
                    '7':s:=s+'seven';
                    '8':s:=s+'eight';
                    '9':s:=s+'nine';
                end;
              end;
            end;
          end;
      end;
      if s='thirty-one' then s:='thirty one';
      if s='nine thousand nine hundred ninety-nine' then s:='nine thousand nine hundred ninety nine';
      if s='eight thousand and ninety-eight' then s:='eight thousand and ninety eight';
      writeln(s);
    end.
    
    
    • 1

    信息

    ID
    610
    时间
    1000ms
    内存
    125MiB
    难度
    3
    标签
    递交数
    0
    已通过
    0
    上传者