Code Golf:音符 [英] Code Golf: Musical Notes

查看:95
本文介绍了Code Golf:音符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按字符数计数的最短代码,它将根据用户输入输出音符.

The shortest code by character count, that will output musical notation based on user input.

输入将由一系列字母和数字组成-字母代表音符的名称,数字代表音符的长度.注释由4个垂直栏组成.音符的头部将为大写字母O,茎(如果存在)将高3行,由竖线字符|制成,并且标记将由反斜杠\制成.

Input will be composed of a series of letters and numbers - letters will represent the name of the note and the number will represent the length of the note. A note is made of 4 vertical columns. The note's head will be a capital O, stem, if present will be 3 lines tall, made from the pipe character |, and the flag(s) will be made from backward slash \.

有效音符长度为无,音符的1/4,音符的1/8,音符的1/16和音符的1/32.

Valid note lengths are none, 1/4 of a note, 1/8 of a note, 1/16 of a note and 1/32 of a note.

       |    |\    |\    |\
       |    |     |\    |\
       |    |     |     |\
 O    O    O     O     O
 1   1/4  1/8  1/16   1/32

笔记是指工作人员在其上的位置,根据其笔记名称而定:

Notes are places on the Staff, according to their note name:

  ----

D ----
C     
B ----
A     
G ----
F     
E ----

可以假定所有输入均有效且没有错误-每个音符在一行中用空格分隔,至少有一个有效音符.

All input can be assumed to be valid and without errors - Each note separated with a white space on a single line, with at least one valid note.

Input:
    B B/4 B/8 B/16 B/32 G/4 D/8 C/16 D B/16
Output:
                              |\               
    --------------------------|---|\--------
          |   |\  |\  |\      |   |\      |\
    ------|---|---|\--|\-----O----|--O----|\
          |   |   |   |\  |      O        | 
    -O---O---O---O---O----|--------------O--
                          |                 
    ---------------------O------------------

    ----------------------------------------


Input:
    E/4 F/8 G/16 A/32 E/4 F/8 G/16 A/32 
Output:

    --------------------------------

    --------------|\--------------|\
              |\  |\          |\  |\ 
    ------|\--|\--|\------|\--|\--|\
      |   |   |  O    |   |   |  O  
    --|---|--O--------|---|--O------
      |  O            |  O          
    -O---------------O--------------


Input:
    C E/32 B/8 A/4 B F/32 B C/16
Output:

    ------------------------------|\
              |\                  |\
    ----------|---|---------------|-
     O        |   |              O   
    ---------O----|--O----|\-O------
          |\     O        |\        
    ------|\--------------|\--------
          |\             O           
    -----O--------------------------

代码计数包括输入/​​输出(即完整程序).

Code count includes input/output (i.e full program).

推荐答案

Golfscript(112个字符)

' '%:A;10,{):y;A{2/.0~|1=~:r;0=0=5\- 7%
4y@--:q'  '' O'if-4q&!q*r*{16q/r<'|\\'
'| 'if}'  'if+{.32=y~&{;45}*}%}%n}%

这篇关于Code Golf:音符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆