A1061 Dating (20 minutes | string processing, annotated in detail, logic analysis)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_24452475/article/details/100565017

EDITORIAL

  • Ideas analysis
    • According to the method found equal to the character determination subject, the output time of less than 2 bits to be added in front of 0, i.e., the output% 02d
  • 10 minutes a title

Test Case

  • input:
    3485djDkxh4hhGE 
    2984akDfkkkkggEdsb 
    s&hgsfdk 
    d&Hyscvnm
    
    output:
    THU 14:04
    

ac Code

  • #include <iostream>
    #include <cctype>
    
    using namespace std;
    int main()
    {
    
        string a, b, c, d;
        cin >> a >> b >> c >> d;
        char t[2];
        int pos, i=0, j=0;
        while(i < a.length() && i<b.length())
        {
            if(a[i]==b[i] && (a[i]>= 'A' && a[i]<='G'))
            {
                t[0] = a[i];
                break;
            }
            i++;
        }
        i = i+1;
        while(i<a.length() && i<b.length())
        {
            if(a[i]==b[i] && ((a[i]>= 'A' && a[i]<='N') || isdigit(a[i])))
            {
                t[1] = a[i];
                break;
            }
            i++;
        }
    
        while(j<c.length() && j<d.length())
        {
            if(c[j]==d[j] && isalpha(c[j]))
            {
                pos = j;
                break;
            }
            j++;
        }
        string week[7] = {"MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};
        int m = isdigit(t[1]) ? t[1]-'0' : t[1]-'A' + 10;
        cout << week[t[0]-'A'];
        printf("%02d:%02d", m, pos);
    
        return 0;
    }
    

Guess you like

Origin blog.csdn.net/qq_24452475/article/details/100565017