Baby Ming and phone number(BC)

来源:互联网 发布:大数据培训班多少钱 编辑:程序博客网 时间:2024/06/05 02:06

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

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


0 0