zoukankan      html  css  js  c++  java
  • 解题报告 Lyric

    Lyric

    【问题描述】
    痛过以后 才知情已难寻
    吾爱至斯 只剩飞花梦影
    回首再望 蜀山依旧伫立
    看尽浮沉 独饮回忆       ——《少年情》

    旋律动听的曲子,伴着意境深远的lyric而显得更加优美。要想学会一首歌,没有一份装订精美的歌词,你让我情何以堪。

    你的任务是,将一份歌词,按照给出规则整理好。

    【输入格式】

    若干行文字(包括按规定格式给出歌曲名,歌词)

    每一行格式为    标识+内容

    标识[name]表示后接歌曲名

    标识[mm:ss]表示后接歌词,其中m,s表示每一位数字,为歌词出现的时间。保证符合正常的计时方式。

    若存在时间相同的歌词,则应按规则依次首尾相连在同一行输出,规则如下:

    1、 长度短的靠前;

    2、 长度相同则字典序小的靠前。

    【输出格式】

    第一行八个空格+歌曲名

    第二行及以后按时间顺序列出歌词

    【输入样例】

    [00:02]she is the heaven-sent angel you met

    [00:05]=.=.=.=.=

    [00:04]she is so pretty all over the world

    [00:01]she is the one that you never forget

    [name]she

    [00:03]oh,she must be the reason why God made a girl

     

    【输出样例】

    she

    she is the one that you never forget

    she is the heaven-sent angel you met

    oh,she must be the reason why God made a girl

    she is so pretty all over the world

    =.=.=.=.=

    【数据hint

    1、 保证歌曲名和歌词均为英文字母,字符。

    2、 保证每一行不超过256个字符

    3、 保证输入不超过2000

     

    注意这句话:

    若存在时间相同的歌词,则应按规则依次首尾相连在同一行输出,规则如下:

    3、 长度短的靠前;

    4、 长度相同则字典序小的靠前。

    我们班几乎所有人都 WA 在了这里。

     

    然后,算法神马的,这个题就一水排序,不说了。

     

    这里放一下 XMC 的代码。

    type

      ll=record

        s:string;

        t:longint;

      end;

    var

      i,j,k,n,m:longint;

      a:array[0..2001] of ll;

      s:ansistring;

      tmp:Longint;

      name:string;

    procedure init;

      begin

        i:=0;

        fillchar(a,sizeof(a),0);

        while not eof do

          begin

            readln(s);

            if s[2]='n' then name:=copy(s,7,length(s)-6)

             else

               begin

                 inc(i);

                 val(s[2]+s[3],tmp);

                 a[i].t:=tmp*100;

                 val(s[5]+s[6],tmp);

                 a[i].t:=a[i].t+tmp;

                 a[i].s:=copy(s,8,length(s)-7);

               end;

          end;

        n:=i;

      end;

    function before(p,t,tt:longint;ss:string):boolean;

     var

     ii:Longint;

      begin

        if a[p].t<t then exit(true)

          else if a[p].t>t then exit(false);

        if length(a[p].s)<tt then exit(true)

          else if length(a[p].s)>tt then exit(false);

        for ii:=1 to tt do

          if a[p].s[ii]<ss[ii] then exit(true)

            else if a[p].s[ii]>ss[ii] then exit(false);

        exit(false);

      end;

    function latter(p,t,tt:longint;ss:string):boolean;

     var

     ii:Longint;

      begin

        if a[p].t>t then exit(true)

          else if a[p].t<t then exit(false);

        if length(a[p].s)>tt then exit(true)

          else if length(a[p].s)<tt then exit(false);

        for ii:=1 to tt do

          if a[p].s[ii]>ss[ii] then exit(true)

            else if a[p].s[ii]<ss[ii] then exit(false);

        exit(false);

      end;

    procedure fast(l,r:Longint);

      var

       i,j:longint;

       tmp:ll;

       t,tt,k:longint;

       ss:string;

      begin

        i:=l;

        j:=r;

        k:=random(r-l+1)+l;

        t:=a[k].t;

        tt:=length(a[k].s);

        ss:=a[k].s;

        repeat

          while before(i,t,tt,ss) do inc(i);

          while latter(j,t,tt,ss) do dec(j);

          if i<=j then

            begin

              tmp:=a[i];

              a[i]:=a[j];

              a[j]:=tmp;

              inc(i);dec(j);

            end;

          until i>j;

        if i<r then fast(i,r);

        if l<j then fast(l,j);

      end;

    procedure main;

      begin

        fast(1,n);

        for i:=1 to 8 do write(' ');writeln(name);

        a[0].t:=a[1].t;

        for i:=1 to n do

          begin

            if a[i].t=a[i-1].t then write(a[i].s)

              else

                begin

                 writeln;

                 write(a[i].s);

                end;

          end;

      end;

    begin

      assign(input,'lyric.in');reset(input);

      assign(output,'lyric.out');rewrite(output);

      randomize;

      init;

      main;

      close(input);

      close(output);

    end.

     

     

     

  • 相关阅读:
    Interview with BOA
    Java Main Differences between HashMap HashTable and ConcurrentHashMap
    Java Main Differences between Java and C++
    LeetCode 33. Search in Rotated Sorted Array
    LeetCode 154. Find Minimum in Rotated Sorted Array II
    LeetCode 153. Find Minimum in Rotated Sorted Array
    LeetCode 75. Sort Colors
    LeetCode 31. Next Permutation
    LeetCode 60. Permutation Sequence
    LeetCode 216. Combination Sum III
  • 原文地址:https://www.cnblogs.com/SueMiller/p/2216458.html
Copyright © 2011-2022 走看看