PTA A_1100 Mars Numbers
C实现#include <stdio.h>
#include <string.h>
char m1 = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
char m2 = {"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, s))
return i;
for (i = 1; i < 13; i++)
if (!strcmp(m2, s))
return -i;
return 0;
}
int main(void)
{
int n, pos, num;
char str = {'\0'}, s = {'\0'};
scanf("%d", &n);
while (n--)
{
getchar();
scanf("%[^\n]", str);
num = 0;
if (str >= '0' && str <= '9')
{
sscanf(str, "%d", &num);
if (num / 13)
{
printf("%s", m2);
if (num % 13)
printf(" %s", m1);
putchar('\n');
}
else
puts(m1);
}
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;
}
页:
[1]