打印选票!


16

众所周知,今天是选举日!

今天的任务是,在有输入的情况下打印选票。

如果输入为Hillary Clinton,则打印:

Hillary Clinton   ===-----===>
Donald Trump      ===     ===>
____________      ===     ===>

但是,如果输入为Donald Trump,则打印:

Hillary Clinton   ===     ===>
Donald Trump      ===-----===>
____________      ===     ===>

如果还有其他问题,请将其写在第三行:

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
Oliver Ni         ===-----===>

(从技术上讲,我还不到18岁...)

请记住,这是,所以字节最少的代码将获胜。


8
没有“以上选项均无”?:)
Kritixi Lithos

@KritixiLithos Hm,nah ...
Oliver Ni

8
“其他”名称上的最大长度是多少?(您的示例中的第一个等号前有18个字符)
链接吴

1
是区分大小写还是不区分大小写?从测试用例来看,我目前认为比较敏感。
凯文·克鲁伊森

@KritixiLithos,但这将操纵系统!
OldBunny2800 '16

Answers:


6

Jelly,55 53字节

³ẇị⁾- x5⁾ =,”=x3¤j;”>ṭ
ṭ“Gụ©l⁴“%eŻƤ(»”_x12¤ṭQḣ3z⁶ZÇ€Y

在线尝试!

说明

³ẇị⁾- x5⁾ =,”=x3¤j;”>ṭ   Helper link. Argument: row
³ẇ                       Check if the user's vote is in this row
  ị⁾-                    Take "-" if it was, " " otherwise
      x5                 Take five of that character
        ⁾ =,”=           Take the array [" =", "="]
              x3         Turn it into ["   ===", "==="]
                ¤        Combine the two previous steps into a nilad
                 j       Join the list by the five character string
                  ;”>    Add ">"
                     ṭ   Prepend the original row

ṭ“Gụ©l⁴“%eŻƤ(»”_x12¤ṭQḣ3z⁶ZÇ€Y   Main link. Argument: vote
 “Gụ©l⁴“%eŻƤ(»                   Take the array ["Hillary Clinton", "Donald Trump"]
ṭ                                Add the user's vote to the list
              ”_                 Take "_"
                x12              Take twelve times that
                   ¤             Combine the two previous steps into a nilad
                    ṭ            Add that string to the list
                     Q           Remove duplicates
                      ḣ3         Take the three first items
                        z⁶       Transpose, padding with spaces
                          Z      Transpose back
                           ǀ    Apply the helper to each row
                             Y   Join with newlines

4

Python 2,127字节

X=['Hillary Clinton','Donald Trump']
i=input()
X+=[[i],['_'*12]][i in X]
for x in X:print x.ljust(18)+'==='+' -'[i==x]*5+'===>'


2

Java 7中,390个 339 335字节

String c(String s){String h="Hillary Clinton",d="Donald Trump",r=h+"   ===Q===>\n"+d+"      ===X===>\nZ===J===>";boolean H=h.equals(s),D=d.equals(s);for(int i=s.length();i++<18;s+=" ");return r.replace(H?"Q":D?"X":"J","-----").replace(H|D?"Z":"~","____________      ").replaceAll(H?"X|J":D?"Q|J":"Q|X","     ").replace(H|D?"~":"Z",s);}

取消测试代码:

在这里尝试。

class M{
  static String c(String s){
    String h = "Hillary Clinton",
           d = "Donald Trump",
           r = h+"   ===Q===>\n"+d+"      ===X===>\nZ===J===>";
    boolean H = h.equals(s),
            D = d.equals(s);
    for(int i = s.length(); i++ < 18; s += " ");
    return r.replace(H?"Q":D?"X":"J", "-----")
            .replace(H|D?"Z":"~", "____________      ")
            .replaceAll(H?"X|J":D?"Q|J":"Q|X", "     ")
            .replace(H|D?"~":"Z", s);
  }

  public static void main(String[] a){
    System.out.println(c("Hillary Clinton"));
    System.out.println();
    System.out.println(c("Donald Trump"));
    System.out.println();
    System.out.println(c("Anyone else?.."));
    System.out.println();
    System.out.println(c("S"));
    System.out.println();
    System.out.println(c("Anyone who is willing to take the job"));
  }
}

输出:

Hillary Clinton   ===-----===>
Donald Trump      ===     ===>
____________      ===     ===>

Hillary Clinton   ===     ===>
Donald Trump      ===-----===>
____________      ===     ===>

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
Anyone else?..    ===-----===>

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
S                 ===-----===>

Hillary Clinton   ===     ===>
Donald Trump      ===     ===>
Anyone who is willing to take the job===-----===>

2

JavaScript(ES6),149字节

s=>['Hillary Clinton','Donald Trump',0].map(S=>((S?S:s||'____________')+p+p+p+p+p).slice(0,18)+`===${!S^S==s?(s=0,'-----'):p}===>`,p='     ').join`
`

演示版


1

V,104字节

OHillary Clinton³ ³=µ ³=>YpRDonald Trump   p15r_ñ/^¨á« ᫾©.*î¨.*î©*\1
22|5r-Gdññ3GjéRDk@"Í_/ 
22|5r-

在线尝试!

这个答案太古怪,太久了。我想这就是从文本编辑器设计高尔夫语言时所得到的。¯\_(ツ)_/¯


等待做O什么?它的功能类似于i
Conor O'Brien

@conor是的,它们都进入了插入模式。唯一的区别是,其中在缓冲区中的光标开始。还有iIaAoOsSR所有人都以某种方式进入插入模式
DJMcMayhem

0

批处理,210字节

@set s=%1
@call:l %1 "Hillary Clinton"
@call:l %1 "Donald Trump"
@call:l %1 %s%
@exit/b
:l
@set v=     
@if %1==%2 set v=-----&set s=____________
@set t=%~2                  
@echo %t:~0,18%===%v%===^>

注意:该行@set v=具有5个尾随空格,而该行@set t=%~2具有18个空格。接受输入作为带引号的命令行参数。


0

C#,266字节

打高尔夫球:

string B(string s){var h="Hilary Clinton".PadRight(17);var d="Donald Trump".PadRight(17);var r="===     ===>\n";var c=r.Replace(" ", "-");var b="____________".PadRight(17);return s==h.Trim()?s.PadRight(17)+c+d+r+b+r:s==d.Trim()?h+r+d+c+b+r:h+r+d+r+s.PadRight(17)+c;}

取消高尔夫:

public string B(string s)
{
  var h = "Hilary Clinton".PadRight(17);
  var d = "Donald Trump".PadRight(17);
  var r = "===     ===>\n";
  var c = r.Replace(" ", "-");
  var b = "____________".PadRight(17);
  return s == h.Trim() ? s.PadRight(17) + c + d + r + b + r :
    s == d.Trim() ? h + r + d + c + b + r :
      h + r + d + r + s.PadRight(17) + c;
}

试图为所有这些PadRights创建一个Func ...完全相同的字节数...

测试:

var printABallot = new PrintABallot();
Console.WriteLine(printABallot.B("Hilary Clinton"));

Hilary Clinton   ===-----===>
Donald Trump     ===     ===>
____________     ===     ===>


Console.WriteLine(printABallot.B("Donald Trump"));

Hilary Clinton   ===     ===>
Donald Trump     ===-----===>
____________     ===     ===>


Console.WriteLine(printABallot.B("Kanye West"));

Hilary Clinton   ===     ===>
Donald Trump     ===     ===>
Kanye West       ===-----===>

0

Python 3.6,132个字节

i=input()
s=['Hillary Clinton','Donald Trump','_'*12]
if x not in s:s[2]=i
for k in s:print(f'{k:18}==={" -"[k==i]*5}===>')

使用3.6的新f字符串


0

Pyth,76个字节

V{+_tW!}zJ[*\_12"Donald Trump""Hillary Clinton")Jzs[.[Nd18K*\=3*?qzN\-d5K\>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.