痛过以后 才知情已难寻
吾爱至斯 只剩飞花梦影
回首再望 蜀山依旧伫立
看尽浮沉 独饮回忆 ——《少年情》
旋律动听的曲子,伴着意境深远的 而显得更加优美。要想学会一首歌,没有一份装订精美的歌词,你让我情何以堪。
你的任务是,将一份歌词,按照给出规则整理好。
题面真有意思…字符串模拟,认真模拟,把所有信息都存在结构题里面,然后根据题意写出合适的 ,排序后,输出判断是否需要回车。
参考代码:
#include <bits/stdc++.h>
using namespace std;
struct Node{
char CH[300];
int Time,Length;
}G[3005];
int Cnt,Name_Cnt;char NAME[300];
bool Cmp(Node P,Node Q){
if(P.Time<Q.Time){
return true;
} else if (P.Time>Q.Time){
return false;
}
if(P.Length<Q.Length){
return true;
} else if (P.Length>Q.Length){
return false;
}
int I,J,K;
for(I=1;I<=P.Length;I++){
if(P.CH[I]<Q.CH[I]){
return true;
} else if (P.CH[I]>Q.CH[I]){
return false;
}
}
return false;
}
int main(){
char CH;
int I,J,K;
while(~scanf("%c",&CH)){
if(CH=='['){
CH=getchar();
}
if(CH=='n'){
while(CH!=']'){
CH=getchar();
}
CH=getchar();
while(CH!='\n'){
NAME[++Name_Cnt]=CH;CH=getchar();
}
continue;
}
++Cnt;
G[Cnt].Time=(G[Cnt].Time<<1)+(G[Cnt].Time<<3)+CH-'0';
CH=getchar();G[Cnt].Time=(G[Cnt].Time<<1)+(G[Cnt].Time<<3)+CH-'0';
CH=getchar();CH=getchar();
G[Cnt].Time=(G[Cnt].Time<<1)+(G[Cnt].Time<<3)+CH-'0';
CH=getchar();G[Cnt].Time=(G[Cnt].Time<<1)+(G[Cnt].Time<<3)+CH-'0';
CH=getchar();CH=getchar();
while(CH!='\n'){
G[Cnt].CH[++G[Cnt].Length]=CH;CH=getchar();
}
}
for(I=1;I<=8;I++){
putchar(' ');
}
for(I=1;I<=Name_Cnt;I++){
putchar(NAME[I]);
}
putchar('\n');
sort(G+1,G+1+Cnt,Cmp);
for(I=1;I<=Cnt;I++){
for(J=1;J<=G[I].Length;J++){
putchar(G[I].CH[J]);
}
if(G[I+1].Time!=G[I].Time){
putchar('\n');
}
}
return 0;
}