Nbut 1189 Join The lyrics Player (string processing)

Source: Internet
Author: User
Tags current time join

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;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.