PTA: Organization Information Week (10 points) (C language)

Enter a positive integer repeat (0 <repeat <10), these times do repeat operations:

Defines an array of pointers to organize the following day of the week, a character string input, lookup tables, if present, the output of the serial number in the string table, and otherwise outputs -1.

Sunday Monday Tuesday Wednesday Thursday Friday Saturday

Example O: described in brackets, without O

Sample input (REPEAT =. 3):
. 3
on Tuesday
catalog on Wednesday
year

Output Sample:
. 3
. 4
-1

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

int main()
{
    char day[7][10] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
    int repeat;
    scanf("%d", &repeat);
    int i, j;
    char str[30];
    for (i = 1; i <= repeat; i++)
    {
        scanf("%s", &str);
        for (j = 0; j < 7; j++)
        {
            if (strcmp(str,day[j]) == 0)
            {
                printf("%d\n", j+1);
                break;
            }                  
        }
        if(j == 7)
            printf("-1\n");
    }
    return 0;
}
Published 58 original articles · won praise 21 · views 610

Guess you like

Origin blog.csdn.net/qq_45624989/article/details/105399479