文章

19

粉丝

225

获赞

20

访问

52.2k

头像
c-结构体数组赋值
P1011 贵州大学机试题
发布于2023年3月24日 11:44
阅读数 2.5k

主要是C语言中字符串不能直接赋值,那么就使用函数strcpy()赋值,然后求天数取余即可。

#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
struct node{
	char w[10];
};
int main(){
	int mon,day;
	scanf("%d",&mon);
	scanf("%d",&day);
	struct node week[7]={NULL};
	strcpy(week[0].w,"Thursday");
	strcpy(week[1].w,"Friday");
	strcpy(week[2].w,"Saturday");
	strcpy(week[3].w,"Sunday");
	strcpy(week[4].w,"Monday");
	strcpy(week[5].w,"Tuesday");
	strcpy(week[6].w,"Wednesday");
	
	//struct node week[7].w={"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
	int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	int sum=0;
	for(int i=4;i<mon;i++){
		sum=sum+m[i];
	}
	sum=sum-12+day;
	int t=sum%7;
	printf("%s",week[t].w);
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发