星空's Blog
星空's Blog
PAT-A1061 Dating

原题

Dating (20 分)

题解

分成几个小任务解决,都很简单

代码

#include <iostream>
#include <map>
using namespace std;

int main(void) {
    map<int,string> mp;
    mp[0] = "MON";
    mp[1] = "TUE";
    mp[2] = "WED";
    mp[3] = "THU";
    mp[4] = "FRI";
    mp[5] = "SAT";
    mp[6] = "SUN";
    string a,b,c,d;
    cin >> a >> b >> c >> d;
    int index = 0;
    for (int i = 0;i < a.length();i++) {
        if (a[i] == b[i] && a[i] >= 'A' && a[i] <= 'G') {
            index = i;
            break;
        }
    }
    cout << mp[a[index] - 'A'] << " ";
    for (int i = index + 1;i < a.length();i++) {
        if (a[i] == b[i] && (a[i] >= '0' && a[i] <= '9' || a[i] >= 'A' && a[i] <= 'N')) {
            index = i;
            break;
        }
    }
    if (a[index] >= '0' && a[index] <= '9') {
        cout << "0" << a[index];
    } else {
        cout << 10 + a[index] - 'A';
    }
    for (int i = 0;i < c.length();i++) {
        if (c[i] == d[i] && (c[i] >= 'a' && c[i] <= 'z' || c[i] >= 'A' && c[i] <= 'Z')) {
            index = i;
            break;
        }
    }
    if (index < 10) {
        cout << ":0" << index << endl;
    } else {
        cout << ":" << index << endl;
    }
    return 0;
}
所有文章禁止转载。
代码仅供参考
为了对抗广告机器人,首次留言将会被审核
https://secure.gravatar.com/avatar/271861a23dcdde929d3ee8cb8c04f854?s=256&d=monsterid&r=g

星空

文章作者

发表评论

textsms
account_circle
email

星空's Blog

PAT-A1061 Dating
原题 Dating (20 分) 题解 分成几个小任务解决,都很简单 代码 #include <iostream> #include <map> using namespace std; int main(void) { map<int,string> mp;…
扫描二维码继续阅读
2019-08-29
分类
标签云