最终幻想XV未覆盖!


9

由于我为《Final Fantasy XV Uncovered》事件大肆宣传,因此我希望编写一个程序告诉我何时发生!

输入

您的汇整输入形式为HH:MM XDT,其中HH是范围内的数字1-12MM是之间的数字0-60,并且XDT是时区,并且XE(东部,UTC-4),C(中央,UTC-5),P(太平洋, UTC-7)或M(山,UTC-6)。这是假定为下午的时间。有效输入包括:

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. 如果转换后的时间是下午六时PDT,打印X minutes until the pre-show!,替换X与到下午6点的PDT的分钟数。

    2. 如果转换后的时间在PDT下午6:00之前和PDT 7:00之前之后,请打印Pre-show started X minutes ago; UNCOVERED is starting in Y minutes!,其中PDTX是自6:00 PM PDT经过Y的分钟数,是7:00之前的分钟数。太平洋夏令时间。

    3. 如果转换的时间在PDT 7:00 PM之后或等于7:00 PM PDT,则打印UNCOVERED started X minutes ago!,这里XPDT 7:00 PM之后经过的分钟数。

每个打印的字符串必须后跟换行符。

计分

这是代码高尔夫,所以最短的程序会获胜。


是否假定所有输入均有效?
Leaky Nun

1
HH:MM XDT错字吗?可以CST
Leaky Nun

1
将会2:45 EDT出现,所以我们需要检测转换的时间是PM还是AM?
Leaky Nun

如果您实际上包括了四个时区的UTC偏移量,那就太好了,这样我就不必亲自查找它们了。
尼尔

@KennyLau这CST是一个错字,不会出现任何时间可以跨越AM / PM边界的情况。编辑帖子。
kirbyfan64sos '16

Answers:


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`}!`)

不知道节省的钱,但是有一些重复的东西可以让你更多地打高尔夫球。例如“重新显示”和“未覆盖”。
马特

@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!希望您在这里过得愉快。
Leaky 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)]
Leaky Nun

欢迎使用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)

在线尝试

取消高尔夫:

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)

当您的数字不是以10为底的其他基数时,您不必使用tonumber,而是可以编写h=h+0,加上0将自动将结果转换为数字。另外,是n=(...)强制性的吗?...如下内联使用-> h,m,t=(...):match("(%d+):(%d+) (.)")会更好,您无论如何都不会重用它,因为您随后更改了nusing hm:) 的值
Katenkyo

同样,您应该能够对形式为的三元声明的if / elseif / else进行更改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!"。可能需要重做一点,但是使用它可以节省很多字节。有关信息,lua中的三元结构为<condition> and <case true, have to be evaluated to true> or <case false, can be anything>
Katenkyo

(仍然没有足够的空间来完成我想说的话)不要忘了检查lua技巧,它们还不是很详尽,但是还有一些有用的东西:)
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在这里不起作用。
Leaky 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);}

删除不必要的换行符(除#define之后的所有换行符)后的333个字节。


不知道可以节省多少,但是您可以添加一些字符串文字,例如“分钟”和“未覆盖”
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条目,从正则表达式中$argv[1]取出$i = [HH, MM],从第一个字符开始确定时区$argv[2],算出6PM PDT之后的分钟数,然后三进制echo

可以使用丢弃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!"}}

少打高尔夫球的解释

# 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!"
    }
}

代码中删除了“以前”的文字,但在其他更改的情况下,现在将其留作解释。


我想我在某些字面上大吃一惊,这使它变得更长了……
马特
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.