PAT 1061. Dating

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1061

题解:

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
void week(char c)
{
    switch(c)
    {
        case 'A':
        {
            printf("MON ");
            break;
        }
        case 'B':
        {
            printf("TUE ");
            break;
        }
        case 'C':
        {
            printf("WED ");
            break;
        }
        case 'D':
        {
            printf("THU ");
            break;
        }
        case 'E':
        {
            printf("FRI ");
            break;
        }
        case 'F':
        {
            printf("SAT ");
            break;
        }
        case 'G':
        {
            printf("SUN ");
            break;
        }
    }
}
void hour(char c)
{
    int num;
    if('0'<=c&&c<='9')
        num=c-'0';
    else
        num=c-'A'+10;
    printf("%02d:",num);
}
int main()
{
    string a,b,c,d;
    int i,len;
    cin>>a>>b>>c>>d;
    len=min(a.length(),b.length());
    for(i=0;i<len;++i)
    {
        if(a[i]<'A'||'G'<a[i]) continue;
        if(a[i]==b[i])
        {
            week(a[i]);
            break;
        }
    }
    for(i=i+1;i<a.length();++i)
    {
        if(('0'<=a[i]&&a[i]<='9')||('A'<=a[i]&&a[i]<='N'))
        {
            if(a[i]==b[i])
            {
                hour(a[i]);
                break;
            }
        }
    }
    len=min(c.length(),d.length());
    for(i=0;i<len;++i)
    {
        if(isalpha(c[i])&&(c[i]==d[i]))
        {
            printf("%02d\n",i);
            break;
        }
    }
    return 0;
}

来源: http://blog.csdn.net/acm_ted/article/details/20142563

你可能感兴趣的:(PAT 1061. Dating)