跟踪清单到时间表


25

介绍

当有人将您喜欢的相册上传到YouTube时,您是否不讨厌它,但是说明中仅包含曲目列表?像这样:

1. Everything in Its Right Place - 4:11
2. Kid A - 4:44
3. The National Anthem - 5:50
4. How to Disappear Completely - 5:55
5. Treefingers - 3:42
6. Optimistic - 5:16
7. In Limbo - 3:31
8. Idioteque - 5:09
9. Morning Bell - 4:29
10. Motion Picture Soundtrack - 6:59

现在您不知道早晨的钟声何时开始,除非您花费大量时间在脑海中!通常,一些善良的人会过去,并在(可怕的)评论部分中留下一个方便的时间表,该时间表如下所示:

(0:00:00) Everything in Its Right Place
(0:04:11) Kid A
(0:08:55) The National Anthem
(0:14:45) How to Disappear Completely
(0:20:40) Treefingers
(0:24:22) Optimistic
(0:29:38) In Limbo
(0:33:09) Idioteque
(0:38:18) Morning Bell
(0:42:47) Motion Picture Soundtrack

规格

  • 您的任务是编写一个程序或函数,该程序或函数将曲目列表作为输入,并将时间表作为输出。

    • 您可以选择从STDIN读取输入,或者从参数字符串或行的参数列表中读取。同样,您可以选择将输出打印到STDOUT,或者返回一个字符串,或者返回一个行列表。如果没有这些,请尽一切可能对您的语言有意义。
  • 您可以假设每个输入行都具有format (\d+)\. [A-Za-z0-9 ]{1,100} - (\d+):(\d\d)。对于正则表达式受损的用户,这实际上意味着您可以假设每一行的格式正确(如上),并且歌曲标题仅由字母数字ASCII字符和空格组成,并且长度不超过100个字节。

  • 曲目的长度始终至少为0:01,且不超过59:59
  • 曲目编号从递增,1直到不超过99
  • 专辑的总长度不超过9:59:59

这是,因此最短的代码(以字节为单位)获胜。

测试用例

您的程序应正确执行介绍中介绍的转换(Radiohead的Kid A)。这是一个更大的测试用例(Sufjan Stevens的Illinois 1),带有长字符串,您的程序也应适用于此:

1. Concerning the UFO Sighting Near Highland Illinois - 2:08
2. The Black Hawk War - 2:14
3. Come On Feel the Illinoise - 6:45
4. John Wayne Gacy Jr - 3:19
5. Jacksonville - 5:24
6. A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons - 0:47
7. Decatur or Round of Applause for Your Stepmother - 3:03
8. One Last Whoo Hoo for the Pullman - 0:06
9. Chicago - 6:04
10. Casimir Pulaski Day - 5:53
11. To the Workers of the Rock River Valley Region - 1:40
12. The Man of Metropolis Steals Our Hearts - 6:17
13. Prairie Fire That Wanders About - 2:11
14. A Conjunction of Drones Simulating the Way - 0:19
15. The Predatory Wasp of the Palisades Is Out to Get Us - 5:23
16. They Are Night Zombies They Are Neighbors They Have Come Back from the Dead Ahhhh - 5:09
17. Lets Hear That String Part Again Because I Dont Think They Heard It All the Way Out in Bushnell - 0:40
18. In This Temple as in the Hearts of Man for Whom He Saved the Earth - 0:35
19. The Seers Tower - 3:53
20. The Tallest Man the Broadest Shoulders - 7:02
21. Riffs and Variations on a Single Note - 0:46
22. Out of Egypt into the Great Laugh of Mankind and I Shake the Dirt from My Sandals as I Run - 4:21

正确的输出是:

(0:00:00) Concerning the UFO Sighting Near Highland Illinois
(0:02:08) The Black Hawk War
(0:04:22) Come On Feel the Illinoise
(0:11:07) John Wayne Gacy Jr
(0:14:26) Jacksonville
(0:19:50) A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons
(0:20:37) Decatur or Round of Applause for Your Stepmother
(0:23:40) One Last Whoo Hoo for the Pullman
(0:23:46) Chicago
(0:29:50) Casimir Pulaski Day
(0:35:43) To the Workers of the Rock River Valley Region
(0:37:23) The Man of Metropolis Steals Our Hearts
(0:43:40) Prairie Fire That Wanders About
(0:45:51) A Conjunction of Drones Simulating the Way
(0:46:10) The Predatory Wasp of the Palisades Is Out to Get Us
(0:51:33) They Are Night Zombies They Are Neighbors They Have Come Back from the Dead Ahhhh
(0:56:42) Lets Hear That String Part Again Because I Dont Think They Heard It All the Way Out in Bushnell
(0:57:22) In This Temple as in the Hearts of Man for Whom He Saved the Earth
(0:57:57) The Seers Tower
(1:01:50) The Tallest Man the Broadest Shoulders
(1:08:52) Riffs and Variations on a Single Note
(1:09:38) Out of Egypt into the Great Laugh of Mankind and I Shake the Dirt from My Sandals as I Run

排行榜

为了使您的分数出现在黑板上,应该采用以下格式:

# Language, Bytes

1.向Sufjan表示歉意,我不得不对其惊人的音轨名称进行一些修改,以使其适合于此问题仅限于的简单格式。


输出中是否可以包含尾随空格?
马丁·恩德

1
Radiohead和Sufjan Stevens?Meh :-P
Luis Mendo

不; 每行的格式为(h:mm:ss) Track Name,紧随其后的是换行符。
林恩

@LuisMendo可以在您的答案中随意展示您卓越的音乐品味...?
林恩

哈哈哈 这是一个很好的回答动机。顺便说一句,我喜欢这个挑战,并且我已经接受了挑战
Luis

Answers:


12

CJam,60 57 55字节

感谢Sp3000节省2个字节。

qN/{T60bZ0e["(%d:%02d:%02d) "e%\S/1>)':/60bT+:T;W<S*N}/

在这里测试。

说明

qN/{      e# Read input and split into lines.
  T60b    e# Push T (initially zero, we use this to keep track of the total time in
          e# seconds), and convert it to base 60.
  Z0e[    e# Pad it with zeroes to 3 digits to get hours, minutes, seconds.
  "(%d:%02d:%02d) "e%
          e# Get the (h:mm:ss) part using a format string.
  \S/     e# Pull up the current line, split on spaces.
  1>      e# Discard the first segment, i.e. the track number.
  )':/    e# Pull off the last segment, i.e. the time, and split on colons.
  60b     e# Interpret the two parts as base-60 digits to get the amount of seconds
          e# for the track.
  T+:T;   e# Add this to T and discard it.
  W<      e# Discard the last segment of the remaining string (the hyphen).
  S*N     e# Join the song name back together with spaces and push a line feed.
}/

16
该死的马丁
-cjfaure

6

Perl,(加上93个字符-p)94个字节

s!\d+\. (.+) - (\d+:(\d+))!sprintf"(%d:%02d:%02d) $1",$n/3600,$n%3600/60,$n%60,$n+=$3+60*$2!e

跑步:

perl -pe 's!\d+\. (.+) - (\d+:(\d+))!sprintf"(%d:%02d:%02d) $1",$n/3600,$n%3600/60,$n%60,$n+=$3+60*$2!e' <<< '<input>'

5

C ++ 212 209 202 189字节

C ++因为..为什么不呢?

#include<iostream>
long d,t,u;main(){std::string a,b(8,0);while(getline(std::cin>>t>>a[0],a,'-')>>t>>b[0]>>u){strftime(&b[0],9,"%T",gmtime(&d));b[0]='(';std::cout<<b+")"+a+'\n';d+=t*60+u;}}

生活: 212 209 202 189


5

Python 2,170 160字节

自从我打高尔夫球已经有一段时间了,希望这还不错:P

t=0
for i in input().split('\n'):i=i.split(' - ');print'(%d:%02d:%02d)'%(t/3600,t%3600/60,t%60),i[0].split('. ')[1];k=i[-1].split(':');t+=int(k[0])*60+int(k[1])

输入应该用引号引起来,并用换行符分隔,如下所示:

"1. Concerning the UFO Sighting Near Highland Illinois - 2:08\n2. The Black Hawk War - 2:14\n3. Come On Feel the Illinoise - 6:45\n4. John Wayne Gacy Jr - 3:19\n5. Jacksonville - 5:24\n6. A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons - 0:47\n7. Decatur or Round of Applause for Your Stepmother - 3:03\n8. One Last Whoo Hoo for the Pullman - 0:06\n9. Chicago - 6:04\n10. Casimir Pulaski Day - 5:53\n11. To the Workers of the Rock River Valley Region - 1:40\n12. The Man of Metropolis Steals Our Hearts - 6:17\n13. Prairie Fire That Wanders About - 2:11\n14. A Conjunction of Drones Simulating the Way - 0:19\n15. The Predatory Wasp of the Palisades Is Out to Get Us - 5:23\n16. They Are Night Zombies They Are Neighbors They Have Come Back from the Dead Ahhhh - 5:09\n17. Lets Hear That String Part Again Because I Dont Think They Heard It All the Way Out in Bushnell - 0:40\n18. In This Temple as in the Hearts of Man for Whom He Saved the Earth - 0:35\n19. The Seers Tower - 3:53\n20. The Tallest Man the Broadest Shoulders - 7:02\n21. Riffs and Variations on a Single Note  - 0:46\n22. Out of Egypt into the Great Laugh of Mankind and I Shake the Dirt from My Sandals as I Run - 4:21"

4
我认为您可以%d为小时计数器(如果我正确理解规则!)-2
Dom Hastings 2015年

加4个字符(inputraw_input)以接受确切的格式;否则,我认为这是无效的,因为它假定行格式不同。
RK。

3

Gema,151个字符

\B=@set{t;}
<D>. * - <D>\:<D>=(@div{$t;3600}:@fill-right{00;@div{@mod{$t;3600};60}}:@fill-right{00;@mod{$t;60}}) *@set{t;@add{@add{$t;$4};@mul{$3;60}}}

样品运行:

bash-4.3$ gema '\B=@set{t;};<D>. * - <D>\:<D>=(@div{$t;3600}:@fill-right{00;@div{@mod{$t;3600};60}}:@fill-right{00;@mod{$t;60}}) *@set{t;@add{@add{$t;$4};@mul{$3;60}}}' tracklist.txt
(0:00:00) Concerning the UFO Sighting Near Highland Illinois
(0:02:08) The Black Hawk War
(0:04:22) Come On Feel the Illinoise
(0:11:07) John Wayne Gacy Jr
(0:14:26) Jacksonville
(0:19:50) A Short Reprise for Mary Todd Who Went Insane but for Very Good Reasons
(0:20:37) Decatur or Round of Applause for Your Stepmother
(0:23:40) One Last Whoo Hoo for the Pullman
(0:23:46) Chicago
(0:29:50) Casimir Pulaski Day

3

Python 2中,207个 206字节

h=m=s=0
for i in raw_input().splitlines():
 print("(%d:%.2d:%.2d) "%(h,m,s),i.split('-')[0].split('. ')[1])
 t=i.split('-')[1].split(':')
 m+=int(t[0]);s+=int(t[1]);r=s//60;s-=r*60;m+=r;r=m//60;m-=r*60;h+=r

用法

$ python test.py
'1. Concerning the UFO Sighting Near Highland Illinois - 2:08\n2. The Black Hawk War - 2:14\n3. Come On Feel the Illinoise - 6:45'
(0:00:00) Concerning the UFO Sighting Near Highland Illinois 
(0:02:08) The Black Hawk War 
(0:04:22) Come On Feel the Illinoise 

您正在使用哪个版本的Python 3?我以为raw_input只有在Python 2存在
林恩

固定。我想我只是习惯键入“ 3”。@Mauris
扎克·盖茨

1

awk,119101字节

{split($NF,t,":");$1=$(--NF)="";--NF;print"("substr(strftime("%H:%M:%S",s,1),2)")"$0;s+=t[1]*60+t[2]}

这是这样的时间比我想的那样。问题在于,这种%H格式无法按照要求设置小时数,因此我需要自己计算小时数。

阿克,我很傻。的结果strftime是错误的,因为我需要告诉它使用UTC时间。减少了18个字节!

119字节版本

{split($NF,t,":");$1=$(--NF)="";--NF;print"("(h||0)":"strftime("%M:%S",s)")"$0;s=(r=s+t[1]*60+t[2])%3600;h=int(r/3600)}
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.