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 n,m;
	string a="Monday",s="Tuesday",d="Wednesday",f="Thursday",g="Friday",h="Saturday",j="Sunday";
	while(cin>>n>>m,n||m){
		if(n==4||n==6||n==9||n==11){
			if(n==4){
				if(m==1||m==8||m==15||m==22||m==29)cout<<f<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<g<<endl;
				else if(m==3||m==10||m==17||m==24)cout<<h<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<"Sunday"<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<"Monday"<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<"Tuesday"<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<"Wednesday"<<endl;
			}
			else if(n==6){
				if(m==1||m==8||m==15||m==22||m==29)cout<<s<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<d<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<f<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<g<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<h<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<j<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<a<<endl;
			}
			else if(n==9){
				if(m==1||m==8||m==15||m==22||m==29)cout<<d<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<f<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<g<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<h<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<j<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<a<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<s<<endl;
			}
			else{
				if(m==1||m==8||m==15||m==22||m==29)cout<<a<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<s<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<d<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<f<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<g<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<h<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<j<<endl;
			}
		}
		else if(n==1||n==3||n==5||n==7||n==8||n==10||n==12){
			if(n==1){
				if(m==1||m==8||m==15||m==22||m==29)cout<<"Thursday"<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<"Friday"<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<"Saturday"<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<"Sunday"<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<"Monday"<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<"Tuesday"<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<"Wednesday"<<endl;
			}
			else if(n==3){
				if(m==1||m==8||m==15||m==22||m==29)cout<<a<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<s<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<d<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<f<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<g<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<h<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<j<<endl;
			}
			else if(n==5){
				if(m==1||m==8||m==15||m==22||m==29)cout<<h<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<j<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<a<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<s<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<d<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<f<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<g<<endl;
			}
			else if(n==7){
				if(m==1||m==8||m==15||m==22||m==29)cout<<f<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<g<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<h<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<j<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<"Monday"<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<"Tuesday"<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<"Wednesday"<<endl;
			}
			else if(n==8){
				if(m==1||m==8||m==15||m==22||m==29)cout<<j<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<a<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<s<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<d<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<f<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<g<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<h<<endl;
			}
			else if(n==10){
				if(m==1||m==8||m==15||m==22||m==29)cout<<g<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<h<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<j<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<a<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<s<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<d<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<f<<endl;
			}
			else{
				if(m==1||m==8||m==15||m==22||m==29)cout<<d<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<f<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<g<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<h<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<j<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<a<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<s<<endl;
			}
		}
		else{
			if(m==1||m==8||m==15||m==22||m==29)cout<<j<<endl;
			else if(m==2||m==9||m==16||m==23)cout<<a<<endl;
			else if(m==3||m==10||m==17||m==24)cout<<s<<endl;
			else if(m==4||m==11||m==18||m==25)cout<<d<<endl;
			else if(m==5||m==12||m==19||m==26)cout<<f<<endl;
			else if(m==6||m==13||m==20||m==27)cout<<g<<endl;
			else if(m==7||m==14||m==21||m==28)cout<<h<<endl;
		}
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
string d[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int x[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int y[12][31];
int main(){
	int a,b;
	while(true){
		cin>>a>>b;
		if(a==0){break;}
		int cnt=0;
		for(int i=0;i<12;i++){
			for(int j=0;j<x[i];j++){
				y[i][j]=cnt;
				cnt++;
			}
		}
		int D=y[a-1][b-1];
		D=(D+4)%7;
		cout<<d[D]<<endl;
	}
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	
	string str[7] = {
		"Monday",
		"Tuesday",
		"Wednesday",
		"Thursday",
		"Friday",
		"Saturday",
		"Sunday"
	};
	int hoge[]={31,29,31,30,31,30,31,31,30,31,30,31};
	int m, d;
	while(1){
		cin>> m>> d;
		if(m==0&&d==0) break;
		int num = d;
		for(int i=0;i<m-1;i++){
			num += hoge[i];
		}
		int day = (2+num)%7;
		cout<< str[day]<< endl;
		
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
using namespace std;

int main(){
    int m, d;
    while (cin>>m>>d){
        if (m == 0) break;
        int dow = 3, num[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        vector<string> str;
        str.push_back("Monday");
        str.push_back("Tuesday");
        str.push_back("Wednesday");
        str.push_back("Thursday");
        str.push_back("Friday");
        str.push_back("Saturday");
        str.push_back("Sunday");

        int sum = 0;
        for (int i=0; i < m-1; i++)
            sum += num[i];
        sum += d+2;
        cout << str[sum%7] << endl;
    }
}