鱼C论坛

 找回密码
 立即注册
查看: 2440|回复: 0

[技术交流] PTA A_1100 Mars Numbers

[复制链接]
发表于 2020-1-27 12:52:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
C实现

  1. #include <stdio.h>
  2. #include <string.h>

  3. char m1[13][5] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
  4. char m2[13][5] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};

  5. int m_find(char s[])
  6. {
  7.     int i;

  8.         for (i = 0; i < 13; i++)
  9.                 if (!strcmp(m1[i], s))
  10.                         return i;        
  11.                         
  12.         for (i = 1; i < 13; i++)
  13.                 if (!strcmp(m2[i], s))
  14.                         return -i;        
  15.         
  16.         return 0;
  17. }

  18. int main(void)
  19. {
  20.         int n, pos, num;
  21.         char str[10] = {'\0'}, s[5] = {'\0'};

  22.         scanf("%d", &n);
  23.         
  24.         while (n--)
  25.         {
  26.                 getchar();
  27.                 scanf("%[^\n]", str);
  28.                
  29.                 num = 0;
  30.                
  31.                 if (str[0] >= '0' && str[0] <= '9')
  32.                 {
  33.                         sscanf(str, "%d", &num);
  34.                         
  35.                         if (num / 13)
  36.                         {
  37.                                 printf("%s", m2[num / 13]);
  38.                                 
  39.                                 if (num % 13)
  40.                                         printf(" %s", m1[num % 13]);
  41.                                 putchar('\n');
  42.                         }
  43.                         else
  44.                                 puts(m1[num % 13]);
  45.                 }
  46.                 else
  47.                 {
  48.                         if (strlen(str) > 5)
  49.                         {
  50.                                 sscanf(str, "%s", s);
  51.                                 num += m_find(s) * -13;
  52.                                 sscanf(str, "%*s %s", s);
  53.                                 num += m_find(s);                                       
  54.                         }
  55.                         else
  56.                                 num += ((pos = m_find(str)) < 0) ? (-pos * 13) : pos;

  57.                         printf("%d\n", num);
  58.                 }
  59.         }
  60.         
  61.         return 0;
  62. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-2 20:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表