Topic Links: Click here~~
Test Instructions:
Give you a LRC lyrics file, where each line is preceded by a number of time labels, and when the current time is greater than or equal to this label and less than the other time label, the output line lyrics.
Then give you a time to output the lyrics that should be output this time.
Problem Solving Ideas:
Look forward from this time until you find a time in the label that appears, and then output the lyrics of the label.
Because of the time-format feature, we can store its state i with an int variable.
Then use the one-dimensional array tim[i] to record the number of lyrics that should be output at this time.
It would be nice to be more careful.
#include <stdio.h> #include <string.h> #include <ctype.h> #define N (char) str[n][2000];
Char tim[1000005];
int loc[n],h,m,s;
BOOL Judge (char *s) {if (*s!= ' [') return 0;
for (int i=1;i<=2;i++) if (!isdigit (* (s+i))) return 0;
if (* (s+3)! = ': ') return 0;
for (int i=4;i<=5;i++) if (!isdigit (* (s+i))) return 0;
if ((* (s+4)-' 0 ') *10 + (* (s+5)-' 0 ') >=60) return 0;
if (* (s+6)! = '. ')
return 0;
for (int i=7;i<=8;i++) if (!isdigit (* (s+i))) return 0;
if (* (s+9)! = '] ') return 0;
return 1;
} int to (int a,int b,int c) {return a*10000 + b*100 + C;} void div (int id,char *s) {int len = 0;
while (judge (S+len)) {sscanf (S+len, "[%d:%d.%d]", &h,&m,&s);
Tim[to (h,m,s)] = ID;
Len + 10;
} Loc[id] = Len;
} int main () {int n,q,ans;
strcpy (Str[0], "**************"); while (~SCANF ("%d%d%*c", &AMp;n,&q)) {memset (tim,0,sizeof (Tim));
for (int i=1;i<=n;i++) {gets (str[i]);
Div (i,str[i]);
} while (q--) {ans = 0;
scanf ("%s", str[n+1]);
SSCANF (str[n+1], "%d:%d.%d", &h,&m,&s);
for (; h>=0;h--) {in (; m>=0;m--) {for (; s>=0;s--)
{int x = Tim[to (h,m,s)];
if (x! = 0) {ans = x;
Goto end;
}} s = 99;
} m = 59;
} end:for (int j=loc[ans];str[ans][j];j++) Putchar (Str[ans][j]);
Putchar (' \ n ');
}} return 0;
}