Scrivi il tuo Death Note


14

Kira ha bisogno del tuo aiuto!


Formato di input:

Date [and/or Time]
Name
Gender
Reason

Formato di output:

<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>.


Dettagli, Dettagli:


Il programma dovrebbe tenere conto almeno dei seguenti formati di input della data:

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

Formati orari:

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

I seguenti formati di input del nome:

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


Casi test:


Ingresso:

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

Produzione:

Tolkien, JRR è morto il 2 settembre 1973.

È morto di polmonite.


DISCLAIMER: Se muore davvero in questa data, è colpa di Kira , non mia.

AGGIORNAMENTO: Stephen Harper non è morto nella data indicata

Ingresso:

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

Produzione:

Harper, Stephen morirà il 21 dicembre 2012 alle 23:59:59.

Harper, Stephen morirà di infarto senza motivo.



Bonus:

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

--

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

Aggiungi <st/nd/rd/th>alla fine di DDper input.


Ah, ho appena finito di leggere questa serie: D Non dovrebbe essere un "attacco di cuore" per "nessun motivo", allora?
Ry,

Uhm, il 2 settembre è il 2/9/11, non il 2/7/11;)
Ry

Il genere non ha alcun effetto sull'output?
Peter Olson,

Inoltre, dobbiamo accettare date prima del 1970?
Peter Olson,

5
Come possiamo chiarire le differenze tra input con GG / MM / AAAA e MM / GG / AAAA?
Peter Olson,

Risposte:


6

Javascript (561)

Questo può probabilmente essere ridotto in modo significativo, ma qui 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]+".");

I / O di esempio:

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

Tolkien, JRR morì il 2 settembre 1973. Morì di polmonite.

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

Tutti moriranno il 18 gennaio 2038 alle 21: 14: 8. Tutti moriranno di Y2K38.

Provalo su JsFiddle .


Voglio solo sottolineare che i="9 November 2003 03:14:08 GMT\nDouglas Adams\nMale\nI forgot";mi dà il 8th of November.
Mateen Ulhaq,

4
@muntoo Questo perché si adatta al tuo fuso orario. Se vivi nel fuso orario GMT, dovrebbe darti il ​​nono.
Peter Olson,

Ho intenzione di biasimare te se muoio per il mio compleanno. : P
nyuszika7h,

5

VB.NET, 727 695

Okay, ho giocato un po 'a golf. Richiede 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

Accetta le date in tutti i casi di test e molti altri formati grazie a Date.Parse. Accetta anche molti sessi (come puoi vedere). Se Kira decide di inserire solo il nome o il cognome della persona, il programma andrà in crash.


sembra che potresti essere in grado di eliminare alcuni byte sostituendo l'argomento diviso con una MonthName(d.Month)chiamata
Taylor Scott

2

CSharp - 463 caratteri

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));}

1

PHP, 509 474 462 461 caratteri

<?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];

Ho aggiunto nuove righe dopo ciascuna, ;ma non le ho contate perché non devono essere presenti.
Se il codice gestisce le date oltre il 19 gennaio 2038 03:14:07, dipende dal fatto che sia eseguito su un computer a 64 bit.


1

VBA, 384 366 byte

golfed

subRoutine completa che accetta input del tipo previsto Variant\Stringe invia il messaggio di nota di morte associato alla finestra immediata di VBE

Nota: VBA non è in grado di gestire i fusi orari senza dichiarare le funzioni dell'API di Windows, quindi poiché questi non sono necessari per la domanda, sono stati esclusi

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

Bonus Verison, 394 376 byte

Versione leggermente modificata di quanto sopra che gestisce tutti i casi bonus ad eccezione dei fusi orari (Correzione per la gestione dei mononimi)

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

sequenza di input e output dei problemi di esempio visti dalla finestra immediata di 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.
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.