Final Fantasy XV ยังไม่ได้เปิด!


9

เนื่องจากฉันถูกสะกดจิตอย่างบ้าคลั่งสำหรับงานFinal Fantasy XV Uncoveredฉันต้องการให้คุณเขียนโปรแกรมเพื่อบอกฉันเมื่อมันเป็น !!!

การป้อนข้อมูล

การป้อนข้อมูลใช้เวลาของคุณในรูปแบบของHH:MM XDTที่HHเป็นตัวเลขที่อยู่ในช่วง1-12, MMเป็นตัวเลขระหว่าง0-60และXDTเป็นโซนเวลาด้วยXการเป็นหนึ่งในE(ตะวันออก UTC-4), C(กลาง UTC-5) P(แปซิฟิก UTC-7) หรือM(ภูเขา UTC-6) นี่เป็นเวลาที่คาดว่าจะเป็น PM อินพุตที่ถูกต้องประกอบด้วย:

1:00 EDT (1 PM Eastern Daylight Time)
4:05 MDT (4:05 PM Mountain Daylight Time)
12:23 PDT (12:23 PM Pacific Daylight Time)
1:10 CDT (1:10 PM Central Daylight Time)

อินพุตอาจถือว่าถูกต้อง

ผลลัพธ์

โปรแกรมของคุณจะต้องทำสิ่งต่อไปนี้:

  1. แปลงเวลาที่กำหนดเป็น PDT และเอาท์พุทIt is XX:XX PM PDT.โดยที่XX:XXเวลาแปลง โปรดทราบว่าคุณไม่จำเป็นต้องจัดการกับกรณีใด ๆ ที่การแปลงเวลาจะข้ามขอบเขต AM / PM

  2. พิมพ์หนึ่งในสิ่งต่อไปนี้:

    1. หากเวลาแปลงก่อน 18.00 น. PDT ให้พิมพ์X minutes until the pre-show!และแทนที่Xด้วยจำนวนนาทีจนถึง 18:00 น PDT

    2. หากเวลาแปลงเป็นหลังหรือเท่ากับ 18.00 น. PDT และก่อน 19:00 น. PDTให้พิมพ์Pre-show started X minutes ago; UNCOVERED is starting in Y minutes!โดยที่Xจำนวนนาทีที่ผ่านไปตั้งแต่ 18:00 น. PDT และYเป็นจำนวนนาทีจนถึง 7:00 น. PM PDT

    3. หากเวลาแปลงเป็นหลังหรือเท่ากับ 7:00 PM PDTให้พิมพ์UNCOVERED started X minutes ago!โดยที่Xจำนวนนาทีที่ผ่านไปตั้งแต่ 7:00 PM PDT

แต่ละสตริงที่พิมพ์จะต้องตามด้วยบรรทัดใหม่

เกณฑ์การให้คะแนน

นี่คือรหัสกอล์ฟดังนั้นโปรแกรมที่สั้นที่สุดชนะ


อินพุตทั้งหมดสันนิษฐานว่าถูกต้องหรือไม่
Leun Nun

1
เป็นHH:MM XDTตัวพิมพ์หรือไม่ CSTมันอาจจะเป็น
Leun Nun

1
จะ2:45 EDTปรากฏดังนั้นเราต้องตรวจสอบว่าเวลาแปลงเป็น PM หรือ AM หรือไม่
Leun Nun

คงจะดีถ้าคุณรวมออฟเซ็ต UTC ของสี่โซนเวลาดังนั้นฉันไม่ต้องค้นหามันเอง
Neil

@KennyLau CSTเป็นคำที่พิมพ์ผิดและไม่มีเวลาปรากฏว่าสามารถข้ามขอบเขต AM / PM ได้ แก้ไขโพสต์
kirbyfan64sos

คำตอบ:


1

JavaScript (ES6), 257 ไบต์

s=>(t=` minutes`,a=s.match(/(\d+):(\d+) (.)/),h=+a[1]+"PMCE".search(a[3]),m=420-h*60-a[2],`It is ${h}:${a[2]} PM PDT
${h<6?m-60+t+` until the pre-show`:h<7?`Pre-show started ${60-m+t} ago; UNCOVERED is starting in ${m+t}`:`UNCOVERED started ${-m+t} ago`}!`)

ไม่ทราบการออม แต่มีสายไม่กี่ที่ซ้ำแล้วซ้ำอีกคุณสามารถเล่นกอล์ฟได้มากขึ้นด้วย ตัวอย่างเช่น "re-show" และ "UNCOVERED"
Matt

@Matt สำหรับสตริงที่ทำซ้ำเมื่อค่าใช้จ่ายเป็น 13 ไบต์เท่านั้นดังนั้นจะต้องมีความยาว 14 ไบต์จึงจะคุ้มค่า "นาที" ได้รับโบนัสเมื่ออยู่ติดกับเวลาและต้องการสี่ครั้ง
Neil

4

Python (335 ไบต์)

t=raw_input().replace(*': ').split();x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;print '%s:%s PM PDT' % tuple(t[:1]);x=t[0]*60+int(t[1]);print ['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)), 'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]

เอาท์พุท:

1:00 MDT
2:00 PM PDT
240 minutes until the pre-show!

6:00 CDT  
8:00 PM PDT
UNCOVERED started 60 minutes ago!

6:50 PDT
6:50 PM PDT
Pre-show started 50 minutes ago; UNCOVERED is starting in 10 minutes!

ยินดีต้อนรับสู่PPCG ! หวังว่าคุณจะมีช่วงเวลาที่ดีที่นี่
Leun Nun

นี่เป็นรุ่นที่แข็งแรงเล่นกอล์ฟยังไม่ทดลองซึ่งเป็น 340 ไบต์:t=raw_input().replace(' ',':').split(':');x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;t[2]='PDT';print'%s:%s PM %s'%tuple(t);x=t[0]*60+int(t[1]);print['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)),'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]
รั่วนูน

ยินดีต้อนรับสู่ PPCG เราหวังว่าคุณจะพบสิ่งที่คุณต้องการที่นี่และจะสนุกกับเวลาของคุณกับเรา! หากคุณมีเวลาและความตั้งใจอย่าลืมใส่รหัสของคุณในแบบที่ไม่ดี (อาจมีความคิดเห็น?) ซึ่งจะช่วยให้ผู้คนเข้าใจรหัสของคุณได้เป็นอย่างดี
Katenkyo

คุณสามารถแทนที่.replace(' ', ':').split(':')ด้วย.replace(*': ').split()การบันทึก 6 ไบต์
Blue


2

Lua, 357 335 332 ไบต์

ขอบคุณ@Katenkyo ที่ตัดออก 22 ไบต์

แข็งแรงเล่นกอล์ฟ:

h,m,t=(...):match("(%d+):(%d+) (.)")f=tonumber h=(f(h)-("PMCE"):find(t))%12+1m=f(m)print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=h<6 and n..a.." until the pre-show!"or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"print(r)

( ลองออนไลน์ )

Ungolfed:

n = "7:10 CST"

h,m,t = n:match("(%d+):(%d+) (.)")
h = (tonumber(h) - ("PMCE"):find(t))%12 + 1
m = tonumber(m)
print("It is "..h..":"..m.." PM PDT.")

n = (6-h)*60-m

if h<6 then
  r=n.." minutes until the pre-show!"
elseif h<7 then
  r="Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!"
else
  r="UNCOVERED started "..(m+(h-7)*60).." minutes ago!"
end

print(r)

คุณไม่ต้องใช้ tonumber เมื่อหมายเลขของคุณไม่ได้อยู่ในฐานอื่นที่ไม่ใช่ 10 แต่คุณสามารถเขียนh=h+0ได้การเพิ่ม 0 จะแปลงผลลัพธ์เป็นตัวเลขโดยอัตโนมัติ นอกจากนี้ยังมีn=(...)ผลบังคับใช้? จะดีกว่าหรือไม่ที่จะรวมการใช้อินไลน์...ดังต่อไปนี้ -> h,m,t=(...):match("(%d+):(%d+) (.)")คุณจะไม่ใช้ซ้ำอีกต่อไปเนื่องจากคุณเปลี่ยนค่าการnใช้hและm:)
Katenkyo

นอกจากนี้คุณควรจะสามารถที่จะเปลี่ยนคุณถ้า / elseif / อื่นแถลงการณ์ ternary r=(h<6 and n.." minutes until the pre-show!" )or h<7 and "Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!" or "UNCOVERED started "..(m+(h-7)*60).." minutes ago!"เดียวของแบบฟอร์ม อาจต้องทำใหม่อีกเล็กน้อย แต่การใช้วิธีนี้จะช่วยประหยัดไบต์ได้มาก สำหรับข้อมูลโครงสร้างของไตรภาคใน<condition> and <case true, have to be evaluated to true> or <case false, can be anything>
ลัวะ

(ยังคงไม่ได้มีพื้นที่ที่จะเสร็จสิ้นสิ่งที่ผมอยากจะบอกว่า) อย่าลืมตรวจสอบเคล็ดลับสำหรับการหลัวพวกเขาจะไม่ครบถ้วนสมบูรณ์ แต่มีบางสิ่งที่มีประโยชน์เล็ก ๆ น้อย ๆ :)
Katenkyo

นี่เป็นวิธีแก้ไขปัญหากอล์ฟที่ไม่ผ่านการทดสอบหากคุณต้องการให้ฐานรวมทุกอย่างที่h,m,t=(...):match("(%d+):(%d+) (.)")h=(h-("PMCE"):find(t))%12+1m=m+0print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=(h<6 and n.." minutes until the pre-show!" )or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"end print(r)เป็นจริง 329 ไบต์;)
Katenkyo

ฉันได้ทำการปรับปรุงแล้ว 0 + m ไม่ทำงานที่นี่
Leun Nun

1

C, 333 ไบต์

#define p printf
char s[9];main(t){gets(s);s[5]=0;s[1]-=2+s[6]%2-s[6]%3;s[1]<48&&(s[1]+=10,--*s);
t=*s*600+s[1]*60+s[3]*10+s[4]-32568;p("It is %s PM PDT.",s);
t<0?p("%d minutes until the pre-show!",-t):t<60?p(
"Pre-show started %d minutes ago; UNCOVERED is starting in %d minutes!",t,60-t):
p("UNCOVERED started %d minutes ago!",t-60);}

333 ไบต์หลังจากลบบรรทัดใหม่ที่ไม่จำเป็นออก (ทั้งหมดยกเว้นหนึ่งบรรทัดหลัง #define)


ไม่แน่ใจเกี่ยวกับการประหยัด แต่คุณมีตัวอักษรสตริงบางตัวคุณอาจเพิ่มเช่น "minutes" และ "UNCOVERED"
Matt

1

PHP, 347 328 327 322 ไบต์

<?=$u="UNCOVERED";$m=" minutes";$s=" started ";$p="re-show";$z=['P'=>0,'M'=>1,'C'=>2,'E'=>3];$i=explode(":",$argv[1]);$h=$i[0]%12-$z[$argv[2][0]];$o=$i[1];$t=60-$o;$a="$s$o$m ago";echo"It is ".(($h+11)%12+1).":$o".($h<0?" A":" P")."M PDT.\n".($h<6?$t."$m until the p$p!":($h<7?"P$p$a; $u is starting in $t$m!":"$u$a!"));?>

มุมมองที่ระเบิด

<?=
  $u = "UNCOVERED";
  $m = " minutes";
  $s = " started ";
  $p = "re-show";
  $z = [ 'P' => 0,
         'M' => 1,
         'C' => 2,
         'E' => 3 ];

  $i = explode(":", $argv[1]);
  $h = $i[0]%12 - $z[$argv[2][0]];
  $o = $i[1];
  $t = 60 - $o;
  $a = "$s$o$m ago";

  echo "It is " . (($h+11)%12+1) . ":$o" . ($h < 0 ? " A" : " P") . "M PDT.\n" .
       ($h < 6 ? $t . "$m until the p$p!"
               : ($h < 7 ? "P$p$a; $u is starting in $t$m!"
                         : "$u$a!"));
?>

php script.php HH:MM XDTทำงานเป็น ใช้เวลาในโซนเวลาและเวลาเป็น$argvรายการ regexes $argv[1]ออกไป$i = [HH, MM]กำหนดเขตเวลาจากตัวอักษรตัวแรกใน$argv[2]คณิตศาสตร์ออกกี่นาทีที่ผ่านมา 6:00 PDT ที่เป็นแล้ว ternariesecho

สามารถวาง 2 ไบต์โดยใช้$u=UNCOVEREDแต่มันเป็นข้อผิดพลาดเดียวที่นี่และฉันชอบที่มันทำงานได้อย่างหมดจด


0

PowerShell 292 ไบต์

$r,$i,$s,$u="re-show"," minutes"," start","UNCOVERED";$h,$m,$z=$args[0]-split":| ";$h=+$h-"PMCE".IndexOf($z[0]);"It is $h`:$m PM PDT.";if(($t=$h*60+$m-360)-lt0){"$($t*-1)$i until the p$r!"}else{if($t-gt59){"$u$s`ed $($t-60)$i ago!"}else{"P$r$s`ed $t$i ago; $u is$s`ing in $(($t-60)*-1)$i!"}}

คำอธิบาย Golfed น้อย

# Some string literals.
$r,$i,$s,$u,$g="re-show"," minutes"," start","UNCOVERED"," ago"
# Get the hours, minutes and zone into variables.
$h,$m,$z=$args[0]-split":| "
# Offset the time based on the passed timezone. 
$h=+$h - "PMCE".IndexOf($z[0])
# Display current PDT time.
"It is $h`:$m PM PDT."

# Based on adjusted time value for PDT determine what string to show. 
# Several string literals were used to save space.
if(($t=$h*60+$m-360)-lt0){
    # Show has not started yet
    "$($t*-1)$i until the p$r!"
}else{
    if($t-gt59){
        # Between 6 and 7
        "$u$s`ed $($t-60)$i$g!"
    }else{
        # It's after 7. Should have check more often. 
        "P$r$s`ed $t$i$g; $u is$s`ing in $(($t-60)*-1)$i!"
    }
}

ตัวอักษรสำหรับ "ที่ผ่านมา" ถูกลบในรหัส แต่ตอนนี้เหลืออยู่ในคำอธิบายในกรณีที่มีการเปลี่ยนแปลงอื่น ๆ


ฉันคิดว่าฉันลงน้ำลงบนตัวอักษรบางตัวและมันทำให้มันยาวขึ้น ....
แมตต์
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.