Escribe tu propia Death Note

14

Kira necesita tu ayuda!


Formato de entrada:

Date [and/or Time]
Name
Gender
Reason

Formato de salida:

<Last Name, First Name> <will die/died> on the <DD><st/nd/rd/th> of <MMM, YYYY> [at <hh:mm:ss TT>].
<He/She> <will die/died> of <Reason>.


Detalles, detalles:


Su programa debe tener en cuenta al menos los siguientes formatos de entrada de fecha:

9 November 2003
9/11/2003
November 9, 2003

Formatos de tiempo:

hh tt
hh TT
hh:mm tt
hh:mm TT
hh:mm:ss tt
hh:mm:ss TT
HH
HH:mm
HH:mm:ss

Los siguientes formatos de entrada de nombre:

first        // Stephen
last         // Harper
first last   // Stephen Harper
last, first  // Harper, Stephen


Casos de prueba:


Entrada:

2 September 1973
J.R.R. Tolkien
Male
pneumonia

Salida:

Tolkien, JRR murió el 2 de septiembre de 1973.

Murió de neumonía.


DESCARGO DE RESPONSABILIDAD: Si realmente muere en esta fecha, es culpa de Kira , no mía.

ACTUALIZACIÓN: Stephen Harper no murió en la fecha indicada

Entrada:

21/12/12 23:59:59             // DD/MM/YY HH:mm:ss
Harper, Stephen               // Last, First
Unknown                       // Gender
a heart attack for no reason  // Reason

Salida:

Harper, Stephen morirá el 21 de diciembre de 2012 a las 11:59:59 p.m.

Harper, Stephen morirá de un ataque al corazón sin ninguna razón.



Prima:

July 21, 1969 02:56:15 GMT
Armstrong, Neil
Male
poisoned moon cheese

--

January 19, 2038 03:14:08 GMT
Everyone
Unknown
Y2K38

Agregue <st/nd/rd/th>al final de DDpara entrada.

Mateen Ulhaq
fuente
Jaja, acabo de terminar de leer esta serie: D ¿No debería ser un "ataque al corazón" por "ninguna razón" entonces?
Ry-
Um, el 2 de septiembre es el 2/9/11, no el 2/7/11;)
Ry-
¿El género no tiene ningún efecto en la salida?
Peter Olson
Además, ¿tenemos que aceptar fechas anteriores a 1970?
Peter Olson
55
¿Cómo desambiguamos entre la entrada con DD / MM / AAAA y MM / DD / AAAA?
Peter Olson

Respuestas:

6

Javascript (561)

Esto probablemente se puede reducir significativamente, pero aquí va:

i=i.split("\n");d=new Date(i[0]);t=d.getDate();z=t%10;t+=z==1?"st":z==2?"nd":z==3?"rd":"th";m=['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];y=d.getFullYear();a=d.getHours();b=d.getMinutes();c=d.getSeconds();l=a&&b&&c?" at "+a+":"+b+":"+c:"";g=d>new Date()?"will die":"died";n=i[1].split(" ");n[1]?n[0][n[0].length-1]==","?n=i[1]:n=n[1]+", "+n[0]:n[0];s=i[2]=="Male"?"He":i[2]=="Female"?"She":n;document.write(n+" "+g+" on the "+t+" of "+m+", "+y+l+".<br>"+s+" "+g+" of "+i[3]+".");

Muestra de E / S:

2 September 1973
J.R.R. Tolkien
Male
pneumonia

Tolkien, JRR murió el 2 de septiembre de 1973. Murió de neumonía.

January 19, 2038 03:14:08 GMT
Everyone
Unknown
Y2K38

Todos morirán el 18 de enero de 2038 a las 21:14: 8. Todos morirán de Y2K38.

Pruébalo en JsFiddle .

Peter Olson
fuente
Solo quiero señalar que i="9 November 2003 03:14:08 GMT\nDouglas Adams\nMale\nI forgot";me da el 8th of November.
Mateen Ulhaq
44
@muntoo Eso se debe a que se ajusta a su zona horaria. Si vives en la zona horaria GMT, debería darte el noveno lugar.
Peter Olson
Voy a culpar que si muero en mi cumpleaños. : P
nyuszika7h
5

VB.NET, 727 695

Vale, jugué un poco al golf. Requiere Option Strict Off.

Module M
Sub Main
Dim d=Date.Parse(Console.ReadLine),n=Console.ReadLine,o=Date.Now,g=Console.ReadLine,r=Console.ReadLine,i=n.IndexOf(" "),f=d.Day Mod 10+(d.Day\10=1)*5,a=Array.IndexOf("male|female|he|she|him|her|guy|girl|boy|lady|man|woman".Split("|"), g.ToLower),b="|st|nd|rd".Split("|"),m="|January|February|March|April|May|June|July|August|September|October|November|December".Split("|")
If n.IndexOf(",")<0 Then n=n.Substring(i+1)&", "&n.Substring(0,i)
g=If(a<0,n,If(a Mod 2,"She","He"))
Console.Write("{0} {11} on the {1}{2} of {3}, {4} at {5}:{6:00}:{7:00}.{8}{9} {11} of {10}.",n,d.Day,If(f<4,b(f),"th"),m(d.Month),d.Year,d.Hour,d.Minute,d.Second,vbCrLf,g,r,If(o<d,"will die","died"))
End Sub
End Module

Acepta las fechas en todos los casos de prueba, y muchos otros formatos gracias a Date.Parse. También acepta muchos géneros (como puedes ver). Si Kira decide poner solo el nombre o el apellido de la persona, el programa se bloqueará.

Ry-
fuente
parece que puede soltar bastantes bytes reemplazando su argumento dividido con una MonthName(d.Month)llamada
Taylor Scott
2

CSharp - 463 caracteres

void Main(){Func<String>c=()=>Console.ReadLine();var d=DateTime.Parse(c());var n=c();if(!n.Contains(",")&&n.Contains(" "))n=n.Split(' ')[1]+", "+n.Split(' ')[0];n+=" ";var g=c().ToLower();g=g.Contains("male")?g.Replace("female","She").Replace("male","He"):"They";var r=c();var f=(DateTime.Now<d);Console.Write(String.Format(n+"{0} on the {1} {2}\n{3} {0} of {4}",(f?"will die":"died"),d.ToString("dddd 'of' MMMM, yyyy"),d.Date==d?"":d.ToString("hh:mm:ss"),g,r));}
Robar
fuente
1

PHP, 509 474 462 461 caracteres

<?for($l=0;$l<4;)$i[$l++]=chop(fgets(STDIN));
putenv('TZ=GMT');
$t=strtotime(preg_match("/(\d+)\/(\d+)\/(\d+)(.*)/",$i[0],$q)?"$q[1]-$q[2]-".($q[3]<100?19+1*($q[3]<70):"").$q[3].$q[4]:$i[0]);
$z=$t<time()?" died":" will die";
$f="jS \of F, Y".($t%86400?" \a\\t g:i:s A":"");
$n=strpos($i[1],',')?$i[1]:explode(" ",$i[1]);
if(is_array($n))$n=$n[1]!=""?$n[1].", ".$n[0]:$n[0];?>
<?=$n."$z on the ".date($f,$t)."\n\n".($i[2][0]==M?He:($i[2][0]==F?She:$n))."$z of ".$i[3];

Agregué nuevas líneas después de cada una, ;pero no las conté, ya que no necesitan estar allí.
Si el código maneja fechas posteriores al 19 de enero de 2038 03:14:07, depende de si se ejecuta en una máquina de 64 bits.

Gareth
fuente
1

VBA, 384366 bytes

Golfed

subRutina completa que toma la entrada del tipo esperado Variant\Stringy envía el mensaje de deathnote asociado a la ventana de VBE inmediata

Nota: VBA es incapaz de manejar zonas horarias sin declarar las funciones de la API de Windows, por lo que, como no son necesarias para la pregunta, se han excluido

Sub x(d,n,g,r)
e=CDate(d)
f=Day(e) Mod 10
w=IIf(e>Now," will die"," died")
i=InStr(1,n," ")
n=IIf(InStr(1,n,","),n,Mid(n,i+1)&", "&Mid(n,1,i-1))
g=LCase(g)
Debug.?n;w" on the "Day(e)Split("th|st|nd|rd","|")(IIf(f>3,0,f))" of "MonthName(Month(e))", "Year(e)IIf(InStr(1,d,":")," at "&TimeValue(d),"")"."vbCr;IIf(g="male","He",IIf(g="female","She",n))w" of "r".
End Sub

Bonison Verison, 394 376 Bytes

Versión ligeramente modificada de lo anterior que maneja todos los casos de bonificación con la excepción de las zonas horarias (corrección para manejar monónimos)

Sub x(d,n,g,r)
e=CDate(d)
f=Day(e) Mod 10
i=InStr(1,n," ")
w=Space(0 ^i)&IIf(e>Now,"will die","died")
n=IIf(InStr(1,n,",")^i,n,Mid(n,i+1)&", "&Mid(n,1,i))
g=LCase(g)
Debug.?n;w" on the "Day(e)Split("th|st|nd|rd","|")(IIf(f>3,0,f))" of "MonthName(Month(e))", "Year(e)IIf(InStr(1,d,":")," at "&TimeValue(d),"")"."vbCr;IIf(g="male","He",IIf(g="female","She",n))w" of "r".
End Sub

Uso

secuencia de entrada y salida de los problemas de ejemplo vistos desde la ventana inmediata de VBE

?Now
01-Jun-17 1:59:35 PM

x "2 September 1973", "J.R.R. Tolkien", "Male", "pneumonia"
Tolkien, J.R.R. died on the 2nd of September, 1973.
He died of pneumonia.

x "21/12/12 23:59:59", "Harper, Stephen", "Unknown", "a heart attack for no reason"
Harper, Stephen died on the 21st of December, 2012 at 11:59:59 PM.
Harper, Stephen died of a heart attack for no reason.

x "July 21, 1969 02:56:15", "Armstrong, Neil", "Male", "poisoned moon cheese"
Armstrong, Neil died on the 21st of July, 1969 at 2:56:15 AM.
He died of poisoned moon cheese.

## Using Bonus Version

x "January 19, 2038 03:14:08","Everyone","Unknown","Y2K38"
Everyone will die on the 19th of January, 2038 at 3:14:08 AM.
Everyone will die of Y2K38.
Taylor Scott
fuente