7-1 组织星期信息 (10分)

输入一个正整数repeat (0

定义一个指针数组将下面的星期信息组织起来,输入一个字符串,在表中查找,若存在,输出该字符串在表中的序号,否则输出-1。

Sunday Monday Tuesday Wednesday Thursday Friday Saturday

输入输出示例:括号内为说明,无需输入输出

输入样例 (repeat=3) :
3
Tuesday
Wednesday
year

输出样例:
3
4
-1

程序1:

#include
#include
int main()
{
    char a[10],*b[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};     //定义一个字符串数组的指针用于存放字符串
    int n,i,j,m=0;
    scanf("%d",&n);
    for(i=0;i=7){                             //j>=7则说明循环正常结束,没有找到相同的字符
            printf("-1\n");
        }
    }
    return 0;
}

程序2(其实和程序一就输出有点不同)

#include
#include
int main()
{
    char a[10],*b[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    int n,i,j,m=0;
    scanf("%d",&n);
    for(i=0;i=7){
            printf("-1\n");
        }
        else{
        	printf("%d\n",j+1);
		} 
    }
    return 0;
}

你可能感兴趣的:(PTA作业,c语言)