소개
누군가가 좋아하는 앨범을 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으로 인쇄하거나 문자열을 리턴하거나 행 목록을 리턴하도록 선택할 수 있습니다. 이것에 실패하면, 당신의 언어에 맞는 것이 무엇이든하십시오.
-
각 입력 줄의 형식이 있다고 가정 할 수 있습니다
(\d+)\. [A-Za-z0-9 ]{1,100} - (\d+):(\d\d)
. 정규 표현식이 손상 된 경우 이는 본질적으로 각 줄의 형식이 적절하고 (위와 같이) 노래 제목이 영숫자 ASCII 문자와 공백으로 만 구성되며 100 바이트를 넘지 않는다는 것을 의미합니다. - 트랙의 길이는 항상 적어도
0:01
이하 여야59:59
합니다. - 트랙 번호는 ~부터 시작하여
1
최대 개수까지 증가합니다99
. - 앨범의 총 길이는 이하 여야
9:59:59
합니다.
이것은 code-golf 이므로 가장 짧은 코드 (바이트)가 이깁니다.
테스트 사례
프로그램은 소개 (Radiohead ‘s 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
var QUESTION_ID=58231,OVERRIDE_USER=3852;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
1. Sufjan의 사과,이 트랙의 간단한 형식에 맞추기 위해 놀라운 트랙 이름을 약간 엉켜서 사용해야했습니다.
답변
CJam, 60 57 55 바이트
2 바이트를 절약 한 Sp3000에 감사합니다.
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.
}/
답변
펄 (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>'
답변
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;}}
답변
파이썬 2, 170160 바이트
내가 골프를 한 이후로 오랜 시간이 되었기를 바랍니다.
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"
답변
관장, 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
답변
파이썬 2, 207206 바이트
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
답변
awk, 119 101 바이트
{split($NF,t,":");$1=$(--NF)="";--NF;print"("substr(strftime("%H:%M:%S",s,1),2)")"$0;s+=t[1]*60+t[2]}
입니다 방법 나는 그것이되고 싶어보다 더 오래. 문제는 %H
요청한 시간 형식 을 지정 하지 않으므로 시간을 직접 계산해야한다는 것입니다.
Ack, 나는 바보입니다. 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)}