A1061 Dating (20 分| 字符串处理,附详细注释,逻辑分析)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_24452475/article/details/100565017

写在前面

  • 思路分析
    • 按照题目所给方法找到相等字符后判断,输出时间不足2位数要在前面添0,即用%02d输出
  • 10分钟a题

测试用例

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

ac代码

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

猜你喜欢

转载自blog.csdn.net/qq_24452475/article/details/100565017