Description
输入一个正整数repeat (repeat<=10),做repeat次下列运算:
定义一个指针数组将下面的星期信息组织起来,输入一个字符串,在表中查找,若存在,输出该字符串在表中的序号,否则输出-1。
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Input
无
Output
无
Sample Input 1
3 Tuesday Wednesday year
Sample Output 1
3 4 -1
Code
#include<stdio.h>
#include<string.h>
int main()
{
int n=0;
char week[7][15] = { "Sunday", "Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday"};
char ch[15]= {0};
scanf("%d", &n);
int num[n];
for (int i = 0; i < n; i++)
{
int count=0;
scanf("%s",ch);
for(int j=0; j<7; j++)
{
count++;
if(strcmp(ch,week[j])==0)
{
num[i]=j+1;
count --;
break;
}
}
if (count == 7)
num[i]=-1;
}
for(int i=0; i<n; i++)
{
printf("%d\n",num[i]);
}
return 0;
}