Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"
)

var sc = bufio.NewScanner(os.Stdin)

//Sliceconvtoi ...
func Sliceconvtoi() []int {
	strs := strings.Split(sc.Text(), " ")

	var ints []int
	var x int

	for _, s := range strs {
		x, _ = strconv.Atoi(s)
		ints = append(ints, x)
	}

	return ints
}

func main() {
	for sc.Scan() {
		i := Sliceconvtoi()

		if i[0] == 0 && i[1] == 0 {
			break
		}

		m := time.Month(i[0])
		d := i[1]
		t := time.Date(2004, m, d, 0, 0, 0, 0, time.Local)
		fmt.Println(t.Weekday())
	}

}

C++: #include <iostream>
using namespace std;
int main(){
	int m,d;
	while(1){
		cin>>m>>d;
		if(m==0||d==0) break;
			  if(m==1&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Thursday"<<endl;
		}else if(m==1&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Friday"<<endl;
		}else if(m==1&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Saturday"<<endl;
		}else if(m==1&&(d==4||d==11||d==18||d==25)){
			cout<<"Sunday"<<endl;
		}else if(m==1&&(d==5||d==12||d==19||d==26)){
			cout<<"Monday"<<endl;
		}else if(m==1&&(d==6||d==13||d==20||d==27)){
			cout<<"Tuesday"<<endl;
		}else if(m==1&&(d==7||d==14||d==21||d==28)){
			cout<<"Wednesday"<<endl;
		}else if(m==2&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Sunday"<<endl;
		}else if(m==2&&(d==2||d==9||d==16||d==23)){
			cout<<"Monday"<<endl;
		}else if(m==2&&(d==3||d==10||d==17||d==24)){
			cout<<"Tuesday"<<endl;
		}else if(m==2&&(d==4||d==11||d==18||d==25)){
			cout<<"Wednesday"<<endl;
		}else if(m==2&&(d==5||d==12||d==19||d==26)){
			cout<<"Thursday"<<endl;
		}else if(m==2&&(d==6||d==13||d==20||d==27)){
			cout<<"Friday"<<endl;
		}else if(m==2&&(d==7||d==14||d==21||d==28)){
			cout<<"Saturday"<<endl;
		}else if(m==3&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Sunday"<<endl;
		}else if(m==3&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Monday"<<endl;
		}else if(m==3&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Tuesday"<<endl;
		}else if(m==3&&(d==4||d==11||d==18||d==25)){
			cout<<"Wednesday"<<endl;
		}else if(m==3&&(d==5||d==12||d==19||d==26)){
			cout<<"Thursday"<<endl;
		}else if(m==3&&(d==6||d==13||d==20||d==27)){
			cout<<"Friday"<<endl;
		}else if(m==3&&(d==7||d==14||d==21||d==28)){
			cout<<"Saturday"<<endl;
		}else if(m==4&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Wednesday"<<endl;
		}else if(m==4&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Thursday"<<endl;
		}else if(m==4&&(d==3||d==10||d==17||d==24)){
			cout<<"Friday"<<endl;
		}else if(m==4&&(d==4||d==11||d==18||d==25)){
			cout<<"Saturday"<<endl;
		}else if(m==4&&(d==5||d==12||d==19||d==26)){
			cout<<"Sunday"<<endl;
		}else if(m==4&&(d==6||d==13||d==20||d==27)){
			cout<<"Monday"<<endl;
		}else if(m==4&&(d==7||d==14||d==21||d==28)){
			cout<<"Tuesday"<<endl;
		}else if(m==5&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Friday"<<endl;
		}else if(m==5&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Saturday"<<endl;
		}else if(m==5&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Sunday"<<endl;
		}else if(m==5&&(d==4||d==11||d==18||d==25)){
			cout<<"Monday"<<endl;
		}else if(m==5&&(d==5||d==12||d==19||d==26)){
			cout<<"Tuesday"<<endl;
		}else if(m==5&&(d==6||d==13||d==20||d==27)){
			cout<<"Wednesday"<<endl;
		}else if(m==5&&(d==7||d==14||d==21||d==28)){
			cout<<"Thursday"<<endl;
		}else if(m==6&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Monday"<<endl;
		}else if(m==6&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Tuesday"<<endl;
		}else if(m==6&&(d==3||d==10||d==17||d==24)){
			cout<<"Wednesday"<<endl;
		}else if(m==6&&(d==4||d==11||d==18||d==25)){
			cout<<"Thursday"<<endl;
		}else if(m==6&&(d==5||d==12||d==19||d==26)){
			cout<<"Friday"<<endl;
		}else if(m==6&&(d==6||d==13||d==20||d==27)){
			cout<<"Saturday"<<endl;
		}else if(m==6&&(d==7||d==14||d==21||d==28)){
			cout<<"Sunday"<<endl;
		}else if(m==7&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Wednesday"<<endl;
		}else if(m==7&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Thursday"<<endl;
		}else if(m==7&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Friday"<<endl;
		}else if(m==7&&(d==4||d==11||d==18||d==25)){
			cout<<"Saturday"<<endl;
		}else if(m==7&&(d==5||d==12||d==19||d==26)){
			cout<<"Sunday"<<endl;
		}else if(m==7&&(d==6||d==13||d==20||d==27)){
			cout<<"Monday"<<endl;
		}else if(m==7&&(d==7||d==14||d==21||d==28)){
			cout<<"Tuesday"<<endl;
		}else if(m==8&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Saturday"<<endl;
		}else if(m==8&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Sunday"<<endl;
		}else if(m==8&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Monday"<<endl;
		}else if(m==8&&(d==4||d==11||d==18||d==25)){
			cout<<"Tuesday"<<endl;
		}else if(m==8&&(d==5||d==12||d==19||d==26)){
			cout<<"Wednesday"<<endl;
		}else if(m==8&&(d==6||d==13||d==20||d==27)){
			cout<<"Thursday"<<endl;
		}else if(m==8&&(d==7||d==14||d==21||d==28)){
			cout<<"Friday"<<endl;
		}else if(m==9&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Tuesday"<<endl;
		}else if(m==9&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Wednesday"<<endl;
		}else if(m==9&&(d==3||d==10||d==17||d==24)){
			cout<<"Thursday"<<endl;
		}else if(m==9&&(d==4||d==11||d==18||d==25)){
			cout<<"Friday"<<endl;
		}else if(m==9&&(d==5||d==12||d==19||d==26)){
			cout<<"Saturday"<<endl;
		}else if(m==9&&(d==6||d==13||d==20||d==27)){
			cout<<"Sunday"<<endl;
		}else if(m==9&&(d==7||d==14||d==21||d==28)){
			cout<<"Monday"<<endl;
		}else if(m==10&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Thursday"<<endl;
		}else if(m==10&&(d==2||d==9||d==16||d==23||d||30)){
			cout<<"Friday"<<endl;
		}else if(m==10&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Saturday"<<endl;
		}else if(m==10&&(d==4||d==11||d==18||d==25)){
			cout<<"Sunday"<<endl;
		}else if(m==10&&(d==5||d==12||d==19||d==26)){
			cout<<"Monday"<<endl;
		}else if(m==10&&(d==6||d==13||d==20||d==27)){
			cout<<"Tuesday"<<endl;
		}else if(m==10&&(d==7||d==14||d==21||d==28)){
			cout<<"Wednesday"<<endl;
		}else if(m==11&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Sunday"<<endl;
		}else if(m==11&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Monday"<<endl;
		}else if(m==11&&(d==3||d==10||d==17||d==24)){
			cout<<"Tuesday"<<endl;
		}else if(m==11&&(d==4||d==11||d==18||d==25)){
			cout<<"Wednesday"<<endl;
		}else if(m==11&&(d==5||d==12||d==19||d==26)){
			cout<<"Thursday"<<endl;
		}else if(m==11&&(d==6||d==13||d==20||d==27)){
			cout<<"Friday"<<endl;
		}else if(m==11&&(d==7||d==14||d==21||d==28)){
			cout<<"Saturday"<<endl;
		}else if(m==12&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Tuesday"<<endl;
		}else if(m==12&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Wednesday"<<endl;
		}else if(m==12&&(d==3||d==10||d==17||d==24||d||31)){
			cout<<"Thursday"<<endl;
		}else if(m==12&&(d==4||d==11||d==18||d==25)){
			cout<<"Friday"<<endl;
		}else if(m==12&&(d==5||d==12||d==19||d==26)){
			cout<<"Saturday"<<endl;
		}else if(m==12&&(d==6||d==13||d==20||d==27)){
			cout<<"Sunday"<<endl;
		}else if(m==12&&(d==7||d==14||d==21||d==28)){
			cout<<"Monday"<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;

int main() {
	int m, d;
	while (cin >> m >> d&&m + d) {
		int days[11] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30 };
		int sum = -1;
		for (int i = 0; i < m - 1; i++) {
			sum += days[i];
		}
		sum += d;
		switch (sum % 7) {
		case 0: cout << "Thursday\n"; break;
		case 1: cout << "Friday\n"; break;
		case 2: cout << "Saturday\n"; break;
		case 3: cout << "Sunday\n"; break;
		case 4: cout << "Monday\n"; break;
		case 5: cout << "Tuesday\n"; break;
		case 6: cout << "Wednesday\n"; break;
		}
	}
}