Costruisci podi ASCII


26

Nelle competizioni sportive, capita spesso che i vincitori siano presentati sul podio, con la persona al primo posto in alto al centro, la persona al secondo posto in altezza media a sinistra e la persona al terzo posto in basso e a destra. Lo ricreamo qui con alcune modifiche speciali.

I podi sono presentati di seguito:

     @---@
     | @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |

Questo costituirà la base per questa sfida. Il prossimo passo è rendere i podi abbastanza larghi da adattarsi alle persone (stringhe ASCII stampabili) che sono su di loro. Tuttavia, vogliamo garantire la bellezza estetica (perché questa è una fantastica opportunità fotografica), quindi ogni podio deve avere la stessa larghezza e la larghezza deve essere dispari. Inoltre, le persone vorranno (ovviamente) stare al centro del podio, quindi le corde devono essere centrate il meglio possibile. (Puoi allinearti a sinistra oa destra e non è necessario che sia coerente.) I podi sopra indicati hanno le dimensioni minime e sono considerati 3larghi.

Ad esempio, dato l'input che ["Tom", "Ann", "Sue"]rappresenta rispettivamente il primo, il secondo e il terzo posto, genera i seguenti podi:

      Tom
     @---@
 Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |

Tuttavia, se Anneinvece Annabbiamo, dovremo passare alla dimensione successiva 5e centrare le stringhe nel miglior modo possibile. Qui sto allineando, quindi la lettera "extra" di Anneè a sinistra del centro, ma puoi scegliere da quale lato allineare.

         Tom
       @-----@
 Anne  |  @  |
@-----@|  |  |
|  @  ||  |  |  Sue
|  |  ||  |  |@-----@
|  |  ||  |  ||  @  |

Andiamo per alcuni nomi più lunghi. Che ne dici di ["William", "Brad", "Eugene"]:

          William
         @-------@
  Brad   |   @   |
@-------@|   |   |
|   @   ||   |   | Eugene
|   |   ||   |   |@-------@
|   |   ||   |   ||   @   |

Qui possiamo vedere che Bradha molto spazio bianco, Eugenemeno, e si Williamadatta perfettamente.

Per un caso di prova più lungo, che ne dici di ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]:

                                     A
                         @-----------------------@
           BC            |           @           |
@-----------------------@|           |           |
|           @           ||           |           | DEFGHIJKLMNOPQRSTUVWXYZ
|           |           ||           |           |@-----------------------@
|           |           ||           |           ||           @           |

Infine, abbiamo il minimo input possibile, qualcosa del tipo ["A", "B", "C"]:

       A
     @---@
  B  | @ |
@---@| | |
| @ || | |  C
| | || | |@---@
| | || | || @ |

  • Input e output possono essere forniti con qualsiasi metodo conveniente .
  • L'input è garantito non vuoto (ovvero, non riceverai mai ""come nome).
  • È possibile stamparlo su STDOUT o restituirlo come risultato di una funzione.
  • È accettabile un programma completo o una funzione.
  • Qualsiasi quantità di spazio bianco estraneo è accettabile, purché i personaggi siano allineati in modo appropriato.
  • Sono vietate le scappatoie standard .
  • Si tratta di quindi si applicano tutte le normali regole del golf e vince il codice più breve (in byte).

Tutti i nomi di lunghezza pari devono essere allineati nella stessa direzione?
— Sparr,

1
Perché i podi nell'output dell'ultimo esempio hanno lunghezza 3 anziché lunghezza 1?
— bruderjakob17,

3
@bruderjakob afferma all'inizio "i podi sopra sono le dimensioni minime e sono considerati 3 larghi"
— rtpax

Risposte:


9

JavaScript (ES8), 196 byte

a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@   |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)

Provalo online!


7

Groovy , 187 , 176 , 156 , 150 byte

f={n->m=n*.size().max()|1;h=' '*(m/2);'30734715746756276647665'*.toLong().sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|",'\n'])[it]}}

Provalo online!

(nota: l'interprete tio groovy non è in grado di gestire gli elenchi di indicizzazione usando valori Long anche se groovy 2.5.6 può. Quindi la risposta tio sta usando *.toShort()invece del *.toLong()quale aggiunge un byte)

Definisce una chiusura fche può essere chiamata tramite:

println(f(['tom','ann','sue']))

dove frestituisce una stringa.

Spiegazione:

Riattivando il codice, abbiamo:

f={n->
  m=n*.size().max()|1
  h=' '*(m/2)
  a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|",'\n']
  '30734715746756276647665'*.toLong().sum{a[it]}
}
  • f={n-> - definire la chiusura f con un parametro in-param n
  • m=n*.size().max()|1 - trova il nome massimo len, binario o in numero dispari
  • h=' '*(m/2) - h conterrà gli spazi del pavimento (m / 2), usati in seguito
  • a=...- crea un elenco di codifica con elementi:
    • indici 0,1,2 - nomi, centrati a max len
    • indice 3 - m + 2 spazi
    • indice 4 - @---@modello, imbottito a len
    • indice 5 - | @ |fantasia, imbottito a len
    • indice 6 - | | |modello, imbottito a len
    • indice 7 - newline
  • '307...'*.toLong().sum{a[it]}- Utilizzare le indicazioni nell'elenco di codifica per creare il risultato. .sumusa il fatto che string + string in groovy è valido.
  • si noti che l'espressione '3073...'*.toLong()utilizza l' *.operatore spread per chiamare toLong()ciascun carattere, restituendo un elenco di numeri.
  • nota nella risposta che la variabile aè stata incorporata, nelines rimosso ecc.

6

Tela , 45 byte

r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵

Provalo qui!

Spiegazione:

r    Center the input, preferring left. Converts to an ASCII-art object
     which pads everything with spaces. This is the bulk of the magic.

 251⁰{ .... }            for each number in [2, 5, 1]:
      |*                 repeat "|" vertically that many times
        @;∔              prepend an "@" - a vertical bar for later
           ;             swap top 2 stack items - put the centered art on top
            J            push the 1st line of it (removing it from the art)
             └           order the stack to [remaining, "@¶|¶|..", currentLine]
              l          get the length of the current line
               2M        max of that and 2
                 2%      that % 2
                   ±├    (-that) + 2
                      ×× prepend (-max(len,2)%2) + 2 spaces
l                 get the length of the new string
 ⇵╷               ceil(len / 2) -1
   -×             repeat "-" that many times - half of the podiums top
     └            order stack to [art, currLine, "@¶|¶|..", "----"]
      +           append the dashes to the vertical bar = "@-----¶|¶|.."
       -α∔        vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
          k       remove the last line of that to make up for the middles shortness
           +      and append that horizontally - half of the podium without the name
            │     palindromize the podium
             ∔    and prepend the name
              ⇵   reverse vertically so the outputs could be aligned to the bottom
               ;  and get the rest of the centered input on top
Finally, 
┐     remove the useless now-empty input
 ++   join the 3 podium parts together
   ⇵  and undo the reversing

Abusi "e non deve essere coerente", rendendolo piuttosto incomprensibile.


Umm ... qualche possibilità di spiegazione?
— Matias Bjarland,

1
@MatiasBjarland sebbene sia principalmente manipolazione dello stack e il resto lo capisco a malapena, lì.
— dzaima,

4

Python 2 , 197 190 byte

n=input()
w=max([3]+map(len,n))
w+=~w%2;W=w+2
S=('{:^%d}'%w).format
x,y,s='@| '
a,b,c=map(S,n);A,B,C=x+'-'*w+x,y+S(x)+y,y+S(y)+y
for l in-~W*s+a,s*W+A,s+b+s+B,A+C,B+C+s+c,C+C+A,C+C+B:print l

Provalo online!

-6 byte, grazie ad Andrew Dunai


Puoi salvare 6 byte sostituendo la riga 5 x,y,p='@| 'e usando pinvece di' '
— Andrew Dunai il

1
@andrewdunai grazie :)
— TFeld il

4

Python 2 , 157 byte

a=input()
i=7
while i:print''.join(([a[k/2]]+list('-@||||    '))[7-i-k].center(max(map(len,a))|1,'- '[i+k!=6]).join('@ |'[cmp(i+k,6)]*2)for k in(2,0,4));i-=1

Provalo online!


3

Carbone , 63 byte

≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@

Provalo online! Il collegamento è alla versione dettagliata del codice. Spiegazione:

≔÷⌈EθLι²η

Calcola il numero di spazi in ciascuna metà di un podio.

F³«

Passa sopra ogni luogo. Si noti che l'ingresso dovrebbe essere nell'ordine 2 °, 1 °, 3 °.

J×ι⁺³⊗η⊗﹪⁻¹ι³

Posiziona all'inizio della riga che avrà il testo.

⟦◧§θι⁺⊕η⊘⊕L§θι⟧

Stampa il testo con abbastanza spaziatura a sinistra per centrarlo.

≔⁻⁷ⅉι

Ottieni l'altezza del podio.

P↓ι@ηP↓ιP↓@@¹ηP↓ι@

Disegna il podio.

Approccio alternativo, anche 63 byte:

≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η

Provalo online! Il collegamento è alla versione dettagliata del codice. Spiegazione:

≔÷⌈EθLι²η

Calcola il numero di spazi in ciascuna metà di un podio.

F³«

Passa sopra ogni luogo. Si noti che l'ingresso dovrebbe essere nell'ordine 2 °, 1 °, 3 °.

J×ι⁺³⊗η⊗﹪⁻¹ι³

Posiziona all'inizio della riga che avrà il testo.

⟦◧§θι⁺⊕η⊘⊕L§θι

Stampa il testo con abbastanza spaziatura a sinistra per centrarlo.

⪫@-@×-η⟧

Crea anche la parte superiore del podio inserendo -s tra i caratteri della stringa @-@per raggiungere la larghezza corretta.

E⁻⁷ⅉ⪫⪫||§|@¬κ× η

Stampa il resto del podio spaziando |opportunamente la s, tranne per il fatto che il personaggio centrale è a @sulla prima riga.


3

R 308 302 299

-6 byte grazie a @JAD
-3 byte grazie a @Guiseppe, ora ho meno di 300 byte

function(a){i=max(1,nchar(a)%/%2)
e=2*i+1
`~`=rep
g=' '
s=g~e+2
b='@'
p='|'
t=c(b,'-'~e,b)
x=c(p,g~i,b,g~i,p)
h=sub(b,p,x)
a=lapply(a,function(q){r=nchar(q);l=(e-r)/2+1;if(r%%2<1)c(g~l,q,g~l+1)else c(g~l,q,g~l)})
cat(s,a[[1]],s,s,t,s,a[[2]],x,s,t,h,s,x,h,a[[3]],h,h,t,h,h,x,fill=length(t)*3,sep='')}

C'è probabilmente un modo migliore per creare il layout; Dovrei provare quali opzioni ho per i frame di dati.

Provalo online



2
ti do il cappello per aver fatto una sfida variabile all'arte asciutta in R ... mai divertente da fare. È possibile salvare 3 byte utilizzando i=max(1,nchar(a)%/%2). La generazione di matrixe l'utilizzo writepotrebbe essere più breve (piuttosto che a data.frame). Suggerisco di usare formatcon j="c"per giustificare automaticamente le cose, ed strrepè utile anche in questo caso. Forse prova la chat di golfR per far rimbalzare le idee?
— Giuseppe,

Sì, non mi ero reso conto di quanto sarebbe stato difficile. Ho imparato un po ', soprattutto dovrei imparare meglio Python o iniziare a imparare il Perl :). Me ne ero dimenticato strrep; Dovrò esaminarlo.
— CT Hall

2

Pulito , 209 byte

import StdEnv,Data.List
k=[' @|||||']
$l#m=max(maxList(map length l))3/2*2+1
=flatlines(transpose[(spaces(n*2)++g)%(0,6)\\n<-[1,0,2],g<-[k:[[c,'-':tl if(i==m/2)k['  '..]]\\c<-cjustify m(l!!n)&i<-[0..]]]++[k]])

Provalo online!


2

Python 2 , 188 byte

a,b,c=l=input()
s=max(map(len,l))/2or 1
A='@'+'--'*s+'-@'
D=(' '*s).join
C=D('|@|')
D=D('|||')
d=str.center
S=s*2+3
for l in' '*S+d(a,S),' '*S+A,d(b,S)+C,A+D,C+D+d(c,S),D+D+A,D+D+C:print l

Provalo online!

-5 grazie a TFeld .


2

PHP, 147 byte

golf 93 byte dalla mia idea iniziale, un semplice avanti <?=:

for(;~$v=_616606256046543440445[++$i];)echo$b="@   || "[$v],str_pad(($v&4?"|@":$argv)[$v&3],max(array_map(strlen,$argv))," -"[!$v],2),$b,"
"[$i%3];

prende i nomi dagli argomenti della riga di comando. Corri con -nro provalo online .
Richiede PHP 7; genera avvisi in PHP 7.2 (e in seguito, presumibilmente). Vedere TiO per una correzione di +5 byte.

Mappatura:

0:@---@     = top border
1,2,3       = $argv with spaces
4: "| | |"  = default
5: "| @ |"  = below top
6: "     "  = empty

abbattersi:

for(;~$v=_616606256046543440445[++$i];)echo # loop through map:
    $b="@   || "[$v],                       # print left border
    str_pad(                                # print padded string:
        ($v&4?"|@":$argv)[$v&3],                # string to be padded
        max(array_map(strlen,$argv)),           # pad length = max argument length
        " -"[!$v],                              # pad with: dashes if top border, spaces else
        2                                       # option: center text (pad on both sides)
    ),
    $b,                                     # print right border
    "\n"[$i%3]                              # add linebreak every three items
;

Il pre-incremento per $imi salva da qualsiasi trucco per le nuove linee.
Il vuoto per 6può anche essere vuoto; quindi l'ho fatto.
Ma usare $argv[0]per la corda del bordo superiore -era il golf più bello di sempre. (e salvato 9 byte!)


2

Vai, 436 byte

Go è terribile per il golf. Ma:

package main;import ("fmt";"os");func main(){;z:=os.Args;f:=3;for i:=1;i<4;i++{;if len(z[i])>f{;f=len(z[i]);};};f+=1-f%2;p:=(f-1)/2+1;b:="@";for j:=0;j<f;j++{;b+="-";};b+="@";x:=fmt.Sprintf("|%*v%*v",p,"@",p,"|");y:=fmt.Sprintf("|%*v%[1]*v",p,"|");fmt.Printf("%*v%*v\n%*v%v\n%*v%*v\n%v%v\n%v%v%*v\n%v%v%v\n%v%v%v",f+2,"",p+1+len(z[1])/2,z[1],f+2,"",b,p+1+len(z[2])/2,z[2],2*f+3-p-len(z[2])/2,x,b,y,x,y,p+1+len(z[3])/2,z[3],y,y,b,y,y,x)}

Suddiviso:

package main
import (
  "fmt"
  "os"
)
func main() {
  z:=os.Args
  f:=3
  for i:=1;i<4;i++{
    if len(z[i])>f{
      f=len(z[i])
    }
  }
  f+=1-f%2
  p:=(f-1)/2+1
  b:="@"
  for j:=0;j<f;j++{
    b+="-"
  }
  b+="@"
  x:=fmt.Sprintf("|%*v%*v",p,"@",p,"|")
  y:=fmt.Sprintf("|%*v%[1]*v",p,"|")

  fmt.Printf("%*v%*v\n%*v%v\n%*v%*v\n%v%v\n%v%v%*v\n%v%v%v\n%v%v%v",
  f+2,"",p+1+len(z[1])/2,z[1],
  f+2,"",b,
  p+1+len(z[2])/2,z[2],2*f+3-p-len(z[2])/2,x,
  b,y,
  x,y,p+1+len(z[3])/2,z[3],
  y,y,b,y,y,x)
}

1

Java 8, 399 394 373 byte

Questa soluzione è probabilmente troppo lunga, ma è una soluzione :)

static String r(String[]p){String s="";int l[]=new int[]{p[0].length(),p[1].length(),p[2].length()},m=Math.max(l[0],Math.max(l[1],l[2]))+2,i,q,j,a,k,t;if(m%2==0)m++;if(m==3)m=5;for(i=0;i<7;i++){for(q=0;q<3;q++)for(j=0;j<m;j++){a=(2*q+1)%3;k=2*a;t=(m-l[a])/2;s+=i==k?j>=t&j<t+l[a]?p[a].charAt(j-t):" ":i==k+1?j%(m-1)==0?"@":"-":i>=k+2?j%(m-1)==0?"|":j==m/2?i==k+2?"@":"|":" ":" ";}s+="\n";}return s;}

5 byte salvati ripetendo direttamente in ordine (a = 1,0,2 invece di q = 0,1,2; a = f (q))

static String r(String[]p){String s="";int l[]=new int[]{p[0].length(),p[1].length(),p[2].length()},m=Math.max(l[0],Math.max(l[1],l[2]))+2,i,j,a,k,t;if(m%2==0)m++;if(m==3)m=5;for(i=0;i<7;i++){for(a=1;a<4;a=a==1?0:a+2)for(j=0;j<m;j++){k=2*a;t=(m-l[a])/2;s+=i==k?j>=t&j<t+l[a]?p[a].charAt(j-t):" ":i==k+1?j%(m-1)==0?"@":"-":i>=k+2?j%(m-1)==0?"|":j==m/2?i==k+2?"@":"|":" ":" ";}s+="\n";}return s;}

21 byte salvati grazie a @KevinCruijssen:

static String r(String[]p){String s="";int l[]=new int[3],m=0,i,j,a,k,t;for(String x:p)l[m++]=x.length();m=Math.max(l[0],Math.max(l[1],l[2]))+2;m+=m%2<1?1:m==3?2:0;for(i=0;i<7;i++,s+="\n")for(a=1;a<4;a=a==1?0:a+2)for(j=0,k=2*a,t=(m-l[a])/2;j<m;j++)s+=i==k?j>=t&j<t+l[a]?p[a].charAt(j-t):" ":i==k+1?j%~-m<1?"@":"-":i>=k+2?j%~-m<1?"|":j==m/2?i==k+2?"@":"|":" ":" ";return s;}

Come suggerito da @KevinCruijssen, si potrebbe anche usare al varposto di StringJava 10+ e salvare alcuni byte extra. Non lo faccio per la semplice ragione che non ho ancora Java 10: D, anche lambda potrebbe essere usato. Ciò ridurrebbe la quantità di byte se non lo assegnassimo ad una Function<String[],String>variabile.

In forma estesa:

static String r(String[]p){
    String s=""; //The string that will be returned
    int l[]=new int[3], //An array containing the lengths of our three names
            m=0, //tmp variable for filling l
            i,j,a,k,t; //some declarations to save a few bytes lateron
    for(String x:p) l[m++]=x.length();
    m=Math.max(l[0],Math.max(l[1],l[2]))+2;
    m+=m%2<1? //ensure odd length of the podests
        1
        :m==3?2:0; //ensure the length is at least 3 (in my code, m is the length of the podests + 2)
    for(i=0;i<7;i++,s+="\n") //iterate by row
        for(a=1;a<4;a=a==1?0:a+2) //iterate by place: a=1,0,2
            for(j=0,k=2*a,t=(m-l[a])/2;j<m;j++) //iterate by column
                //k is the row number from top in which the a-th name goes
                //t is the column at which the name starts
                //now, append the right char:
                s+=i==k? //write the name
                    j>=t&j<t+l[a]?
                        p[a].charAt(j-t)
                        :" "
                    :i==k+1? //write the top of the podest ("@---@")
                        j%~-m<1?
                            "@"
                            :"-"
                    :i>=k+2? //write the bottom of the podest ("|  |@  |")
                        j%~-m<1? //the left and right edge of the podest
                            "|"
                            :j==m/2? //the center of the podest
                                i==k+2? //are we at the first row of the bottom?
                                    "@" //the case where we have to write "| @ |"
                                    :"|" //the case "| | |"
                                :" "
                        :" "
                ;
    return s;
}

L'input deve essere dato come String-array di lunghezza 3. Un esempio è simile al seguente:

public static void main(String[] args){
    System.out.print(r(new String[]{"Anthony", "Bertram", "Carlos"}));
}

Produzione:

          Anthony          
         @-------@         
 Bertram |   @   |         
@-------@|   |   |         
|   @   ||   |   | Carlos  
|   |   ||   |   |@-------@
|   |   ||   |   ||   @   |

1
Bella risposta, e benvenuto in PPCG! +1 da me! Ecco alcune cose di base per giocare a golf per renderlo 342 byte : Java 8+ lambda invece del metodo normale; Java 10+ varinvece di String; ha riempito l'array di lunghezza con un ciclo for-each; modificato if(m%2==0)m++;if(m==3)m=5;in m+=m%2<1?m==2?3:1:0per lo stesso effetto; cambiato tutto %nr==0in %nr<1; ha cambiato %(m-1)in %~-m; mettere tutto all'interno del loop stesso in modo che le parentesi {}possano essere rimosse.
— Kevin Cruijssen,

Se non l'hai ancora visto, Suggerimenti per giocare a golf in Java e Suggerimenti per giocare a golf in <tutte le lingue> potrebbero essere entrambi interessanti da leggere. Goditi la permanenza!
— Kevin Cruijssen,

@KevinCruijssen va bene, grazie mille! Aggiornerò il post!
— bruderjakob17,

Suggerisci m-l[a]>>1invece di (m-l[a])/2e i<k+2?" ":j%~-m<1?"|":j==m/2?i==k+2?"@":"|"invece dii>=k+2?j%~-m<1?"|":j==m/2?i==k+2?"@":"|":" "
— ceilingcat

1

C (GCC) 302 293 292 289 287 byte

-6 byte grazie a ceilingcat

#define P(h,n)r=w+2-L[n];i/h?printf("%*s%*s%*s",-~r/2,D,L[n],i>h?D:N[n],r/2,D):printf(~i/h?"@%s@":"|%*s%c%*s|",~i/h?D+1:w/2,D,i>h-3?64:'|',w/2,D);
f(int**N){char L[3],w=3,i=3,r,D[99]={};for(;i--;)w=w<(L[i]=strlen(N[i]))?L[i]|1:w;memset(D+1,45,w);for(i=7;i--;puts(D)){P(4,1)P(6,0)P(2,2)}}

Eseguilo qui

Non risolto e spiegato (tecnicamente non puoi avere commenti dopo le barre rovesciate nelle macro, quindi non funzionerà)

#define P(h,n)\
    r=w+2-L[n];\ //get leftover width
    i/h?\ //if i >= h
        printf("%*s%*s%*s",-~r/2,D,L[n],i>h?D:N[n],r/2,D):\//if too high print all spaces, otherwise center the name
        printf(~i/h?"@%s@":"|%*s%c%*s|",~i/h?D+1:w/2,D,i>h-3?64:'|',w/2,D);
//if (i == h - 1) print top row using D calculated if row right below top, else print '@'(64) in center, otherwise '|'
f(int**N){
    char
        L[3],//lengths of each string
        w=3,//width (init to minimum)
        i=3,//index, used in for loops
        l,//left padding
        r,//right padding
        D[99]={};//string of '-' of correct length (max 99) but first char is null for empty string
    for(;i--;)//i was set to 3 before, i will be {2,1,0}
        w=w<(L[i]=strlen(N[i]))?//set length to str len and compare to longest width so far
            L[i]|1://set it to length if longer, but make sure it is odd
            w;//do not replace
    memset(D+1,45,w); //set the first w bits of D to '-', leaves a null terminator
    for(i=7;i--;puts(D)){//i will be {6...0}
        P(4,1)//print second place, 4 high
        P(6,0)//print first place, 6 high
        P(2,2)//print thrid place, 2 high
    }
}

Ecco il codice chiamante

int main()
{
  char* N[3] = {"Tom", "Anne", "Sue"} ;
  f(N);
}

e uscita

         Tom         
       @-----@       
  Anne |  @  |       
@-----@|  |  |       
|  @  ||  |  |  Sue  
|  |  ||  |  |@-----@
|  |  ||  |  ||  @  |

Suggerisci for(;i--;memset(D+1,45,w))w=w<(L[i]=strlen(N[i]))?L[i]|1:w;invece difor(;i--;)w=w<(L[i]=strlen(N[i]))?L[i]|1:w;memset(D+1,45,w);
— ceilingcat

1

PowerShell per Windows, 231 223 byte

param($a)$w=($a|% le*|sort)[-1]
if(3-gt$w){$w=3}$w+=1-$w%2
0..6|%{$r=$_
-join($a|%{$m=' -'[5-eq($o=$r+2*(++$i%3))]
$e='     @|||||'[$o]
$x=(,''*4+$_,'','@'+,'|'*4)[$o]
"$e$($x|% *ft(($x.Length+$w)/2-.1)$m|% *ht $w $m)$e"})}

Provalo online!

L'input è array @('second','first','third'). Versione non srotolata:

param($arr)
$width=($arr|% length|sort)[-1]
if(3-gt$width){$width=3}
$width+=1-$width%2

0..6|%{ $row=$_                         # 7 rows
    -join($arr|%{                       # 3 joined columns. Each column array contains 11 lines.
        $offset = $row+2*(++$i%3)       # (2,4,0) -> offset in column array #   0:
        $middle = ' -'[5-eq$offset]                                         #   1:
        $edge   = '     @|||||'[$offset]                                    #   2:
        $center = ('','','','',$_,'','@','|','|','|','|')[$offset]          #   3:
                                                                            #   4:  name
        # pad $x to a center                                                #   5: @---@
        $center = $center|% PadLeft (($center.Length+$width)/2-.1) $middle  #   6: | @ |
        $center = $center|% PadRight $width $middle                         #   7: | | |
                                                                            #   8: | | |
        # add the $edge                                                     #   9: | | |
        "$edge$center$edge"                                                 #  10: | | |
    })
}

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.