|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
C实现
- #include <stdio.h>
- #include <string.h>
- char m1[13][5] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
- char m2[13][5] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
- int m_find(char s[])
- {
- int i;
- for (i = 0; i < 13; i++)
- if (!strcmp(m1[i], s))
- return i;
-
- for (i = 1; i < 13; i++)
- if (!strcmp(m2[i], s))
- return -i;
-
- return 0;
- }
- int main(void)
- {
- int n, pos, num;
- char str[10] = {'\0'}, s[5] = {'\0'};
- scanf("%d", &n);
-
- while (n--)
- {
- getchar();
- scanf("%[^\n]", str);
-
- num = 0;
-
- if (str[0] >= '0' && str[0] <= '9')
- {
- sscanf(str, "%d", &num);
-
- if (num / 13)
- {
- printf("%s", m2[num / 13]);
-
- if (num % 13)
- printf(" %s", m1[num % 13]);
- putchar('\n');
- }
- else
- puts(m1[num % 13]);
- }
- else
- {
- if (strlen(str) > 5)
- {
- sscanf(str, "%s", s);
- num += m_find(s) * -13;
- sscanf(str, "%*s %s", s);
- num += m_find(s);
- }
- else
- num += ((pos = m_find(str)) < 0) ? (-pos * 13) : pos;
- printf("%d\n", num);
- }
- }
-
- return 0;
- }
复制代码 |
|