codevs 1772 歌词

1772 歌词

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 白银 Silver
 
 
 
题目描述 Description

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


旋律动听的曲子,伴着意境深远的歌词 而显得更加优美。要想学会一首歌,没有
一份装订精美的歌词,你让我情何以堪。
你的任务是,将一份歌词,按照给出规则整理好。

输入描述 Input Description

若干行文字(包括按规定格式给出歌曲名,歌词)
每一行格式为标识+内容
标识[name]表示后接歌曲名
标识[mm:ss]表示后接歌词,其中m,s表示每一位数字,为歌词出现的时间。保证符
合正常的计时方式。
若存在时间相同的歌词,则应按规则依次首尾相连在同一行输出,规则如下:
长度短的靠前;
长度相同则字典序小的靠前。

输出描述 Output Description

第一行八个空格+歌曲名
第二行及以后按时间顺序列出歌词

样例输入 Sample Input

[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

样例输出 Sample Output

        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
=.=.=.=.=

数据范围及提示 Data Size & Hint

保证歌曲名和歌词均为英文字母,字符。
保证每一行不超过256 个字符
保证输入不超过2000 行

分类标签 Tags 

 
枚举
 
//这题有毒!
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{char r[300];int tt,ss,cd;}q[2005];
bool cmp(const node&a,const node&b)
{
    if(a.tt!=b.tt) return (a.tt<b.tt);
    if(a.ss!=b.ss) return (a.ss<b.ss);
    if(a.cd!=b.cd) return (a.cd<b.cd);
    for(int i=0;i<a.cd;i++)
        if(a.r[i]!=b.r[i]) return (a.r[i]<b.r[i]);
    return 1;
}
int main()
{
    int h=0,pl=0,i,k;
    char a,b,c;
    while(scanf("%c",&c)!=EOF)
    {
        if(c=='['&&pl==0)
        {
            scanf("%c%c",&a,&b);
            if(a=='n') 
            {
                q[h].ss=0;q[h].tt=0;
                while(c!=']') scanf("%c",&c);
                continue;
            }
            else
            {
                q[h].tt=((int)(a))*10+((int)(b));
                scanf(":%d]",&q[h].ss);
                continue;
            }
        }
        if(c=='
')
        {
            q[h].cd=pl;
            pl=0;
            h++;
            continue;
        }
        q[h].r[pl++]=c;
    }
    q[h].cd=pl;
    h++;
    sort(q,q+h,cmp);
    for(i=0;i<8;i++) printf(" ");
    for(i=0;i<h;i++)
    {
        int j;
        for(j=0;j<q[i].cd;j++)
        {
            if(q[i].r[j]>='A'&&q[i].r[j]<='z') printf ("%c",q[i].r[j]);
            if(q[i].r[j]==' '||q[i].r[j]=='-'||q[i].r[j]==','||q[i].r[j]=='='||q[i].r[j]=='.')
                printf ("%c",q[i].r[j]);
        }
        if(i==h-1) return 0;
        if(q[i+1].tt==q[i].tt&&q[i+1].ss==q[i].ss) continue;
        printf("
");
    }
    /*为什么这样不对呢???为什么提交零分呢? 
    for(int i=0;i<h;i++)
    {
        printf("%s",q[i].r);
        if(q[i+1].tt==q[i].tt&&q[i+1].ss==q[i].ss) ;
        else printf("
");
    }*/
    return 0;
}
原文地址:https://www.cnblogs.com/EvilEC/p/5974811.html