zoukankan      html  css  js  c++  java
  • 习题11-1 输出月份英文名 (15 分)

    本题要求实现函数,可以返回一个给定月份的英文名称。

    函数接口定义:

    char *getmonth( int n );

    函数getmonth应返回存储了n对应的月份英文名称的字符串头指针。如果传入的参数n不是一个代表月份的数字,则返回空指针NULL。

    裁判测试程序样例:

    #include <stdio.h>
    
    char *getmonth( int n );
    
    int main()
    {
        int n;
        char *s;
    
        scanf("%d", &n);
        s = getmonth(n);
        if ( s==NULL ) printf("wrong input!
    ");
        else printf("%s
    ", s);
    
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */

    输入样例1:

    5

    输出样例1:

    May

    输入样例2:

    15

    输出样例2:

    wrong input!

    提交:

    #include <stdio.h>
    
    char *getmonth( int n ){
        char *month[13] = {"0","January", "February","March","April","May", "June","July","August","September","October","November","December"
                };
        if (n <1 || n > 12) return NULL;
        else return month[n];
    };
    
    int Main()
    {
        int n;
        char *s;
    
        scanf("%d", &n);
        s = getmonth(n);
        if ( s==NULL ) printf("wrong input!
    ");
        else printf("%s
    ", s);
    
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */
  • 相关阅读:
    详解 注解
    线段树分治
    实用Trick
    CF932F(李超线段树+dp)
    CF24D Broken robot(高斯消元)
    LCT学习笔记
    [HNOI2008]GT考试
    [AHOI2009]中国象棋
    [APIO2012]派遣
    CF961G Partitions
  • 原文地址:https://www.cnblogs.com/cgy-home/p/15039217.html
Copyright © 2011-2022 走看看