Days in Month
Question :-
https://www.codechef.com/problems/NW1
Solution in C language :-
#include <stdio.h>
#include<string.h>
int main(void) {
// your code goes here
int q,i;
scanf("%d",&q);
for(i=0;i<q;i++){
int temp , j , w , c=1 , a[7]={ };
char s[6]="\0";
scanf("%d",&w);
scanf("%s",s);
if(strcmp(s,"mon")==0){
temp=0;
a[0]=1;
}
else if(strcmp(s,"tues")==0){
a[1]=1;
temp=1;
}
else if(strcmp(s,"wed")==0){
a[2]=1;
temp=2;
}
else if(strcmp(s,"thurs")==0){
a[3]=1;
temp=3;
}
else if(strcmp(s,"fri")==0){
a[4]=1;
temp=4;
}
else if(strcmp(s,"sat")==0){
a[5]=1;
temp=5;
}
else if(strcmp(s,"sun")==0){
a[6]=1;
temp=6;
}
for(j=1;j<=w;j++){
a[temp]=c;
if(temp==6){
temp=-1;
}
if(j%7==0){
c++;
}
temp++;
}
for(int j=0;j<7;j++){
printf("%d ",a[j]);
}
printf("\n");
}
return 0;
}
https://www.codechef.com/problems/NW1
Solution in C language :-
#include <stdio.h>
#include<string.h>
int main(void) {
// your code goes here
int q,i;
scanf("%d",&q);
for(i=0;i<q;i++){
int temp , j , w , c=1 , a[7]={ };
char s[6]="\0";
scanf("%d",&w);
scanf("%s",s);
if(strcmp(s,"mon")==0){
temp=0;
a[0]=1;
}
else if(strcmp(s,"tues")==0){
a[1]=1;
temp=1;
}
else if(strcmp(s,"wed")==0){
a[2]=1;
temp=2;
}
else if(strcmp(s,"thurs")==0){
a[3]=1;
temp=3;
}
else if(strcmp(s,"fri")==0){
a[4]=1;
temp=4;
}
else if(strcmp(s,"sat")==0){
a[5]=1;
temp=5;
}
else if(strcmp(s,"sun")==0){
a[6]=1;
temp=6;
}
for(j=1;j<=w;j++){
a[temp]=c;
if(temp==6){
temp=-1;
}
if(j%7==0){
c++;
}
temp++;
}
for(int j=0;j<7;j++){
printf("%d ",a[j]);
}
printf("\n");
}
return 0;
}
Comments
Post a Comment