Due nomi


14

Una persona ha due nomi se il suo cognome è anche un nome comune. Hai il compito di determinare quali nomi completi in un elenco sono due nomi.

John Smith
John Doe
Luke Ryan
Ryan Johnson
Jenna Jackson
Tom John

Qualsiasi nome che compare nella colonna del nome è potenzialmente un nome. Se il numero di occorrenze del nome nella colonna del nome è maggiore del numero di occorrenze nella colonna del cognome, è sicuramente un nome.

Nell'elenco sopra, Johnappare due volte nei nomi e una volta nei cognomi, quindi è sicuramente un nome. Ryanappare una volta nel primo e una volta nell'ultimo, quindi è (probabilmente) un nome.

Pertanto, Tom Johnha sicuramente due nomi e Luke Ryanprobabilmente lo fa.

Dato l'elenco sopra, il codice dovrebbe generare quanto segue:

Luke Ryan has two first names
Tom John definitely has two first names

Ingresso

Come accennato in precedenza, il codice prenderà un elenco di nomi completi (dall'input standard, uno per riga) separati da spazi. I nomi possono includere trattini o apostrofi, ma non ti verrà mai assegnato un nome o un cognome che includa spazi (ovvero no Liam De Rosa, ma Liam De-Rosao Liam De'Rosasiano un gioco leale. In altre parole, i nomi corrisponderanno [-'A-Za-z]+.

Ogni nome completo sarà unico (cioè John Smithnon comparirà due volte).

Produzione

Stampa i nomi completi (una volta per riga) seguiti da uno has two first nameso definitely has two first namesse soddisfano i criteri sopra. I nomi devono essere stampati una sola volta.

I nomi che non sono due nomi non devono essere stampati.

È necessario conservare il caso e i caratteri speciali del nome.

Esempi

Ingresso

Madison Harris
Riley Hudson
Addison Hills
Riley Phillips
Scott Hill
Levi Murphy
Hudson Wright
Nathan Baker
Harper Brooks
Chloe Morris
Aubrey Miller
Hudson Lopez
Samuel Owen
Wyatt Victoria
Brooklyn Cox
Nathan Murphy
Ryan Scott

Produzione

Riley Hudson definitely has two first names
Ryan Scott has two first names

Ingresso

Owen Parker
Daniel Hall
Cameron Hall
Sofia Watson
Mia Murphy
Ryan Jones
Emily Ramirez

Produzione

[no output]

Ingresso

Olivia Robinson
Jacob van-Dyke
Jacob Ella
Brayden De'Rosa
Levi Brook
Brook Bella
Ella Hill
Ella Anderson
Brook-Anne van-Dyke

Produzione

Jacob Ella definitely has two first names
Levi Brook has two first names

Note e punteggio

In bocca al lupo!


Non Johnsonconta come John, o è diverso?
NoOneIsHere

2
Johnsonsarebbe diverso da John. I nomi devono corrispondere esattamente.
Moose,

1
Come scegliamo tra definitely has two first namese has two first names? Può essere sempre uno di quelli?
Rod

Viene visualizzato solo definitelyse il nome compare più volte nella colonna del nome rispetto alla colonna del cognome. Questo caso ha la precedenza, quindi visualizza solo definitely has two first names. Guarda gli esempi.
Moose,

2
Quanto è flessibile il formato di input? Può essere una serie di stringhe, una per persona? O una matrice 2D di stringhe?
Luis Mendo,

Risposte:


6

Java (OpenJDK 8) , 238 222 221 220 212 byte

l->{for(String n:l){int k=0,j=0,q=0;for(String b=n.split(" ")[1];k<l.length;j+=l[k++].matches(b+" .*")?1:0)q+=l[k].endsWith(" "+b)?1:0;if(j>0)System.out.println(n+(j>q?" definitely":"")+" has two first names");}}

Provalo online!


Bello! Puoi comprimere le tue inizializzazioni in k=j=q=0. Inoltre, non ti farà risparmiare alcun byte ma potresti sostituirlo x+=y?1:0con if(y)x++. Se ti piace ottimizzare la leggibilità dopo la lunghezza come me, è probabilmente la strada da percorrere.
Jakob,


6

Python 2 , 141 137 132 130 byte

-2 byte grazie a @JonathanFrech

n=map(str.split,input())
for f,l in n:
 c=cmp(*[x.count(l)for x in zip(*n)])
 if~c:print f,l,'definitely '*c+'has two first names'

Provalo online!


Penso che -c<1possa essere ~c, in quanto cnon sembra essere mai positivo.
Jonathan Frech,

3

AWK , 127 123 byte

{a[$1]++
b[L[++X]=$2]++
N[X]=$0}END{for(;++i<=X;)if(A=a[L[i]])print N[i],(b[L[i]]<A?"definitely ":"")"has two first names"}

Salvataggio di 1 byte non utilizzando il NRvalore incorporato .

Provalo online!


3

Perl 5 , 120 118 + 2 ( -al) = 120 byte

$f{$F[0]}++;$l{$k{$_}=$F[1]}++}{map{print$_.' definitely'x($f{$t}>$l{$t})." has two first names"if$f{$t=$k{$_}}}keys%k

Provalo online!


3

Rubino , 105 129 byte

+24 byte perché ho perso parte delle specifiche

->a{a.map{|e|l=e[r=/\S+$/];i=a.count{|n|n[/\S+/]==l};e+"#{' definitely'if i>a.count{|n|n[r]==l}} has two first names"if i>0}-[p]}

Provalo online!


3

Python 2 , 140 127 122 131 byte

N=map(str.split,input())
F,L=zip(*N)
for f,l in N:
 if l in F:print f,l,'definitely '*(F.count(l)>L.count(l))+'has two first names'

Provalo online!


@ShreevatsaR, Ah, ho letto male. Grazie :)
TFeld,

2

05AB1E, 144 byte (Lavori in corso)

|vy#Dθˆн})©gF®®NèQO¯®NèQO-D®¯NèQO¯¯NèQO-D.À>0›s>0›&i0›s0›&i®Nè" "¯Nè" defínítely has two fírst names"J,ë®Nè" "¯Nè" has two fírst names"J,}ë\\}}´

4
No funziona, sto solo lavorando per ridurre il numero di byte
David Smith,

2

05AB1E , 53 51 byte

|UXv“€°‚•€ÛŒî“D„´Î ì)yð«ìõ¸ìXð¡øεy#θQO}`.S>sèˆ}¯õK»

Provalo online!

Spiegazione

|                                                       # Take inputs as array
 UX                                                     # Store in X and push X to stack
   v                                          }         # For each name, do
    “€°‚•€ÛŒî“D                                         #   Push "has two first names" twice
               „´Î ì                                    #   Prepend "definitely " to one of those
                    )yð«ì                               #   Wrap both strings in an array and prepend (name + " ") to each
                         õ¸ì                            #   Prepend " " to array
                            Xð¡øεy#θQO}`                #   Get occurences in input first and last names
                                        .S>             #   0 for not first name, 1 for first name and 2 for definitely first name
                                           sèˆ          #   Get string at that index and push to global array
                                               ¯õK»     # Output global array, 1 string per line

O 51 49 byte, assumendo regole I / O standard (input e output come array)

UXv“€°‚•€ÛŒî“D„´Î ì)yð«ìõ¸ìXð¡øεy#θQO}`.S>sèˆ}¯õK

Provalo online!


1

PHP, 172 byte

for(;$s=$argv[++$i];$f[$a]++,$l[$n[]=$b]++)[$a,$b]=explode(" ",$s);for(;$b=$n[+$k++];)$f[$b]<$l[$b]||print$argv[$k].($f[$b]>$l[$b]?" definetly":"")." has two first names
";

accetta i nomi come argomenti della riga di comando separati.

Corri con -nro provalo online .


0

Python 3, 187 byte

n={}
c=[]
while 1:
 try:a,b=input().split();n[a]=n.get(a,0)+1;n[b]=n.get(b,0)-1;c+=[[a,b]]
 except:[print(a,b,'definitely has two first names'[(n[b]>0)*11:])for a,b in c if n[b]>=0];break

0

R , 207 byte

n=readLines("stdin")
s='definitively has two first names\n'
x=matrix(t(unlist(sapply(n,strsplit,' '))),2)
j=1
for(i in n){a=apply(x[2,j]==x,1,sum)
b=a[2]>=a[1]
if(a[1])cat(paste(i,substr(s,14*b,34)))
j=j+1}

Provalo online!


0

JavaScript (ES6), 149 byte

s=>s.replace(/(.*) (.*)\n/g,(_,t,u)=>g(`
${u} `)>1?t+` ${u}${v>g(` ${u}
`)?` definitely`:``} has two first names
`:``,g=u=>v=`
${s}`.split(u).length)

L'I / O include la nuova riga finale. In gran parte ispirato alla risposta di @ RobertoGraham.


0

Haskell , 144 140 139 byte

g.map words.lines
g s=id=<<[n++' ':f++[c|c<-" definitely",t 0>t 1]++" has two first names\n"|[n,f]<-s,let t i=filter(==f)$map(!!i)s,[]<t 0]

Provalo online!


0

PowerShell, 176 byte

$n=$args
$s=" has two first names"
$f=$n|%{$_.Split()[0]}
$l=$n|%{$_.Split()[1]}
$i=0
$l|%{switch(($f-match$_).count){{$_-eq1}{$n[$i]+$s}{$_-gt1}{$n[$i]+" definitely"+$s}}$i++}
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.