实验11-1-3 查找星期 (15 分)

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

#define MAXS 80

int getindex(char *s);

int main()
{
    int n;
    char s[MAXS];

    scanf("%s", s);
    n = getindex(s);
    if (n == -1) printf("wrong input!\n");
    else printf("%d\n", n);

    system("pause");
    return 0;
}

/* 你的代码将被嵌在这里 */
int getindex(char *s) {
    char *days[7] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    for (int i = 0; i < 7; i++)
        if (strcmp(s, days[i]) == 0)
            return i;
    return -1;
}

 

posted @ 2022-03-08 09:22  JamesGordan  阅读(59)  评论(0)    收藏  举报