1061. Dating (20)-PAT甲级真题 第三个点的注意

传送门
今日水题呜呜呜
这题注意读题和考虑边界条件, 边界条件非常严苛
第三个点,必须判断是在0-9 a-n直接同时cnt=1的条件, 不过这属于代码数写方式的特例, 不同代码可能不会遇到这样的, 其他的点的问题可以看别的博主, 我这里就不赘述了

#include<bits/stdc++.h>
#define FAST ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
#define debug(a) cout << #a << ":" << a <<endl
#define For(i,x,y) for(int i=(x); i<=(y); ++i)

const int MAX = 2e5+7;
using namespace std;
int n,m;
int arr[MAX];
string day[8] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main(void) {
    string str[4];
    for(int i=0; i<4; i++){
        cin >>str[i];
       // debug(str[i]);
    }
    int cnt=0;
    int len0 = str[0].length(),len1 = str[1].length(),len2 = str[2].length(),len3 = str[3].length();
    int firstTwo = len0 > len1 ? len1: len0;
    int lastTwo  = len2 > len3 ? len3: len2;
    int d,h,m=0;
    for(int i=0; i<firstTwo; i++){
            //debug(i);
        if(str[0][i]==str[1][i]) {
            if(cnt==0&&(str[0][i] >= 'A' && str[0][i]<='G')) {//abcdefg
                cnt++;
                d = str[0][i]-'A';
            } else if( cnt==1&&((str[0][i] >= 'A' && str[0][i]<='N')||(isdigit(str[0][i])))) { // 注意从这里开始,如果替换为文末的代码是不能过的
                if(str[0][i] >= 'A' && str[0][i]<='N') h = str[0][i]-'A'+10;
                else if(isdigit(str[0][i])) h = str[0][i]-'0';
                cnt++;
                break;
            }
            //debug(cnt);
        }

    }
    for(int i=0; i<lastTwo; i++){
            //debug(i);
        if(str[2][i]==str[3][i]&&isalpha(str[2][i])) {
            //debug(cnt);
            if(cnt==2) {
                m = i;
                break;
            }
        }

    }
    cout << day[d];
    printf(" %02d:%02d",h,m);
    return 0;
}
 } else if( cnt==1) {
                if(str[0][i] >= 'A' && str[0][i]<='N') h = str[0][i]-'A'+10;
                else if(isdigit(str[0][i])) h = str[0][i]-'0';
                break;
            }
            //debug(cnt);
        }

    }
    for(int i=0; i<lastTwo; i++){
            //debug(i);
        if(str[2][i]==str[3][i]&&isalpha(str[2][i])) {
            cnt++;
            //debug(cnt);
            if(cnt==2) {
                m = i;
                break;
            }
        }

    }
    cout << day[d];
    printf(" %02d:%02d",h,m);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值