第18周
作者:互联网
课后1
#include<stdio.h> int dt[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int isr(int year) { if(year%4==0 && year%100!=0 || year%400==0) return 1; else return 0; } int main() { int n; int y,m,d; int sum; scanf("%d",&n); while(n--) { sum=0; scanf("%d %d %d",&y,&m,&d); if(isr(y)==1) dt[2]=29; else dt[2]=28; for(int i=1;i<m;i++) { sum+=dt[i]; } sum+=d; printf("%d\n",sum); } return 0; } 课后2 #include <stdio.h> #include <stdlib.h> #include "test.h" #include<string.h>
void registerStaff(int n,staff *head) { int i; for(i=0;i<n;i++) { staff *s=(staff*)malloc(sizeof(staff)); scanf("%d %d %d %s",&s->id,&s->age,&s->wages,s->name); s->next=NULL; head->next=s; head=s; } } void getMaxWages(staff *head) { staff *p,*q,*pre,*c; q=head; p=head->next; int m=-999; while(p!=NULL) { if(m<p->wages) { pre = q; c =p; m=p->wages; } q=p; p=p->next; } pre->next = c->next; c->next = head->next; head->next = c; } 课后3
#include <stdio.h> #include<stdlib.h> #include "test.h"
void insertStaff(staff *head){ staff*p=(staff*)malloc(sizeof(staff)); scanf("%d%d%d %s",&p->id,&p->age,&p->wages,p->name); p->next=NULL; staff*q=head; while(q->next!=NULL){ q=q->next; } q->next=p; }
void deleteStaff(staff *head,int id){ staff*curr=head->next,*pre=head; while(curr!=NULL&&curr->id!=id){ curr=curr->next; pre=pre->next; } if(curr!=NULL){ pre->next=curr->next; free(curr); } }
int getTotalStaff(staff *head){ staff*p=head->next; int sum=0; while(p!=NULL){ sum++; p=p->next; } return sum; }
int getAvgWages(staff *head){ if(getTotalStaff(head)==0){ return 0; } staff*p=head->next; int totalwages=0; while(p!=NULL){ totalwages+=p->wages; p=p->next; } return totalwages/getTotalStaff(head); }
int getMaxAge(staff *head){ staff*p=head->next,*temp=p; if(p==NULL){ return 0; } int MaxAge=p->age; while(p!=NULL){ if(p->age>MaxAge){ temp=p; MaxAge=p->age; } p=p->next; } return MaxAge; } 巩固1 #include<stdio.h> struct std { int a; int b; }; int main() { int n,s,i,j; struct std a[105]; struct std t; while ( scanf( "%d %d",&n ,&s)&&!(n==0 && s==0) ) { for ( i=0;i<n;i++ ) { scanf( "%d%d",&a[i].a,&a[i].b ); } for ( i=0;i<n;i++ ) { for ( j=0;j<n-i-1;j++ ) { if ( a[j].b>a[j+1].b ) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for ( i=0;i<n;i++ ) { if ( s<a[i].b ) break; else s+=a[i].a; } if (i==n) printf( "YES\n" ); else printf( "NO\n" ); } return 0; } 巩固2 #include<stdio.h>
int main() { int m,n,t=0;; scanf("%d%d",&m,&n); for(int i=m/5;i>=0;i--) { for(int j=0;j<=n;j++) { for(int k=n;k>=0;k--) { if(i+j+3*k==n && 5*i+3*j+k==m) { printf("%d %d %d\n",i,j,3*k); t=1; } } } } if(t==0) printf("no answer\n"); return 0; } 巩固3 #include<stdio.h>
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int isr(int year) { if(year%4==0 && year%100!=0 || year%400==0) return 1; else return 0;
}
int main() { int y,fd,m; int c[13];
scanf("%d %d %d",&y,&fd,&m); if(isr(y)==1) d[2]=29; c[1]=fd; for(int i=2;i<=12;i++) { c[i]=(c[i-1]+d[i-1])%7; }
int t=0; switch(m) { case 1:printf("January ");break; case 2:printf("February ");break; case 3:printf("March ");break; case 4:printf("April ");break; case 5:printf("May ");break; case 6:printf("June ");break; case 7:printf("July ");break; case 8:printf("August ");break; case 9:printf("September ");break; case 10:printf("October ");break; case 11:printf("November ");break; case 12:printf("December ");break; } printf("%d\n",y); printf(" Sun Mon Tue Wed Thu Fri Sat\n"); for(int j=1;j<=c[m];j++) { printf(" ");t++; } for(int k=1;k<=d[m];k++) { printf("%8d",k); t++; if(t==7) { printf("\n"); t=0; } } return 0; }
标签:head,int,18,31,next,printf,staff 来源: https://www.cnblogs.com/BraveNullNull/p/15759906.html