Baby Ming and phone number(BC)

水题,但是做的时候犯了个极其脑残的错误。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = ~0U >> 1;
const int maxn = 1000;
typedef long long LL;
int T, n, a, b;
char str[maxn];

bool judge(int x) {
    if(x % 400 == 0 || (x % 4 == 0 && x % 100 != 0)) return true;
    else return false;
}

bool check() {
    int ch = atoi(str + 3);
    int year = ch / 10000;
    int month = (ch % 10000) / 100;
    int day = (ch % 10000) % 100;
    if(year < 1980 || year > 2016) return false;
    if(month <= 0 || month > 12) return false;
    if(day == 0) return false;
    if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        if(day > 31) return false;
    }
    if(month == 4 || month == 6 || month == 9 || month == 11) {
        if(day > 30) return false;
    }
    if(month == 2) {
        if(judge(year)) {
            if(day > 29) return false;
        } else {
            if(day > 28) return false;
        }
    }
    return true;
}

int main() {
    scanf("%d", &T);
    while(T--) {
        LL ans = 0;
        scanf("%d", &n);
        scanf("%d%d", &a, &b);
        for(int x = 0; x < n; ++x) {
            scanf("%s", str);
            bool ok1 = true, ok2 = true, ok3 = true;
            int len = strlen(str);
            for(int i = len - 1; i > len - 5; --i) {
                if(str[i] != str[i-1]) ok1 = false;
            }

            int d = str[len-1] - str[len-2];
            if(d != 1 && d != -1) ok2 = false;
            else {
                for(int i = len - 1; i > len - 5; --i) {
                    if(str[i] - str[i-1] != d) {
                        ok2 = false;
                    }
                }
            }
            if(!check()) ok3 = false;
            if(ok1 || ok2 || ok3) ans += a;
            else ans += b;
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值