fork download
#include <stdio.h>
#include<string.h>
int main(void) {
 int c, m, d, i, m1[13]={31,31,28,31,30,31,30,31,31,30,31,30,31};
 char s[10], w[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
 scanf("%d",&c);
 while(c--){
  scanf("%d%d%s",&m,&d,s);
  for(i=0;i<7;i++)
   if(strcmp(w[i],s)==0) 
    break;
  //printf("%s\n",w[i]);
  d-=i;
  if(d<1){
   m-=1;
   //if(m%2==1) d+=31;
   //else if(m==2) d+=28;
   //else d+=30;
   d+=m1[m];
  }
  printf("%d",d++);
  for(i=0;i<6;i++){
   if(d>m1[m])
    //if((m==2)||(m%2==0&&d>30)||(d>31))
     d=1;
   printf(" %d",d++);
  }
  printf("\n");
 }
 return 0;
}
Success #stdin #stdout 0s 2252KB
stdin
5
7 27 Saturday
7 27 Sunday
7 28 Sunday
7 28 Monday
7 29 Tuesday
stdout
21 22 23 24 25 26 27
27 28 29 30 31 1 2
28 29 30 31 1 2 3
27 28 29 30 31 1 2
27 28 29 30 31 1 2