Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴一个不用字符串比较的短代码,效率也不错

Posted by Eov_Second at 2016-11-21 18:30:14 on Problem 1008
取月份前两个字母的和作为索引打表,只有一个重复特判一下就行了
#include <stdio.h>
char* Tzo[] = { "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };
int HaabMap[] = { 0, 0, 0, 0, 0, 0, 220, 0, 0, 160, 260, 0, 240, 0, 0, 300, 0, 0, 0, 0, 360, 0, 340, 0, 0, 200, 140, 20, 0, 0, 0, 0, 280, 40, 0, 0, 0, 0, 120, 60, 0, 0, 0, 100, 80 };
int findm(char* p) {
    int a = p[0] + p[1] - 194;
    if (24 == a) {
        if (p[0] == 'y') return 180;
        else return 320;
    }
    return HaabMap[a];
}
int main() {
    int n, i=0;
    scanf("%d", &n);
    printf("%d\n", n);
    while (i++ < n) {
        int d, y;
        char m[10];
        scanf("%d. %s %d", &d, m, &y);
        int days = y * 365 + findm(m) + d;
        int tm = days % 260;
        printf("%d %s %d\n", (tm % 13) + 1, Tzo[(tm % 20)], days / 260);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator