I am trying this codechef problem where I need to count the number of occurrences of all days of the week. It's working fine except in case of Thursday and Sunday cause I guess it is comparing only initials. Can somebody help me with this?
#include<stdio.h>
#include<string.h>
int main(){
int t,days,i=0;
char day[6];
int more=0;
char *week[]={"mon", "tues", "wed", "thurs", "fri", "sat", "sun"};
// int occurances[]={4,4,4,4,4,4,4};
printf("Enter number of times loop should run\n");
scanf("%d",&t);
printf("Number of times loop should run=%d\n",t);
while(i<t){
int occurances[]={4,4,4,4,4,4,4};
i++;
printf("Enter number of days of month\n");
scanf("%d",&days);
printf("Enter first day of month\n");
scanf("%s",&day);
for(int p=0;p<7;p++){
if(*week[p]==*day){
more=days-28;
while(more>0){
occurances[(7+p)%7]+=1;
more--;
p++;
}
}
}
for(int l=0;l<7;l++){
printf("%d\t",occurances[l]);
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire