Task: Discordian date

C: #include <stdlib.h>
#include <stdio.h>
#include <time.h>
 
#define day_of_week( x ) ((x) == 1 ? "Sweetmorn" :\
                          (x) == 2 ? "Boomtime" :\
                          (x) == 3 ? "Pungenday" :\
                          (x) == 4 ? "Prickle-Prickle" :\
                          "Setting Orange")
 
#define season( x ) ((x) == 0 ? "Chaos" :\
                    (x) == 1 ? "Discord" :\
                    (x) == 2 ? "Confusion" :\
                    (x) == 3 ? "Bureaucracy" :\
                    "The Aftermath")
 
#define date( x ) ((x)%73 == 0 ? 73 : (x)%73)
 
#define leap_year( x ) ((x) % 400 == 0 || (((x) % 4) == 0 && (x) % 100))
 
char * ddate( int y, int d ){
  int dyear = 1166 + y;
  char * result = malloc( 100 * sizeof( char ) );
 
  if( leap_year( y ) ){
    if( d == 60 ){
      sprintf( result, "St. Tib's Day, YOLD %d", dyear );
      return result;
    } else if( d >= 60 ){
      -- d;
    }
  }
 
  sprintf( result, "%s, %s %d, YOLD %d",
           day_of_week(d%5), season(((d%73)==0?d-1:d)/73 ), date( d ), dyear );
 
  return result;
}
 
 
int day_of_year( int y, int m, int d ){
  int month_lengths[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
  for( ; m > 1; m -- ){
    d += month_lengths[ m - 2 ];
    if( m == 3 && leap_year( y ) ){
      ++ d;
    }
  }
  return d;
}
 
 
int main( int argc, char * argv[] ){
  time_t now;
  struct tm * now_time;
  int year, doy;
 
  if( argc == 1 ){
    now = time( NULL );
    now_time = localtime( &now );
    year = now_time->tm_year + 1900; doy = now_time->tm_yday + 1;
  } else if( argc == 4 ){
    year = atoi( argv[ 1 ] ); doy = day_of_year( atoi( argv[ 1 ] ), atoi( argv[ 2 ] ), atoi( argv[ 3 ] ) );
  }
 
  char * result = ddate( year, doy );
  puts( result );
  free( result );
 
  return 0;
}


C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iterator>
using namespace std;
class myTuple
{
public:
    void set( int a, int b, string c ) { t.first.first = a; t.first.second = b; t.second = c; }
    bool operator == ( pair<int, int> p ) { return p.first == t.first.first && p.second == t.first.second; }
    string second() { return t.second; }
private:
    pair<pair<int, int>, string> t;
};
class discordian
{
public:
    discordian() {
        myTuple t;
        t.set( 5, 1, "Mungday" ); holyday.push_back( t ); t.set( 19, 2, "Chaoflux" ); holyday.push_back( t );
        t.set( 29, 2, "St. Tib's Day" ); holyday.push_back( t ); t.set( 19, 3, "Mojoday" ); holyday.push_back( t );
        t.set( 3, 5, "Discoflux" ); holyday.push_back( t ); t.set( 31, 5, "Syaday" ); holyday.push_back( t );
        t.set( 15, 7, "Confuflux" ); holyday.push_back( t ); t.set( 12, 8, "Zaraday" ); holyday.push_back( t ); 
        t.set( 26, 9, "Bureflux" ); holyday.push_back( t ); t.set( 24, 10, "Maladay" ); holyday.push_back( t ); 
        t.set( 8, 12, "Afflux" ); holyday.push_back( t ); 
        seasons.push_back( "Chaos" ); seasons.push_back( "Discord" ); seasons.push_back( "Confusion" ); 
        seasons.push_back( "Bureaucracy" ); seasons.push_back( "The Aftermath" );
        wdays.push_back( "Setting Orange" ); wdays.push_back( "Sweetmorn" ); wdays.push_back( "Boomtime" );
        wdays.push_back( "Pungenday" ); wdays.push_back( "Prickle-Prickle" ); 
    }
    void convert( int d, int m, int y ) {
        if( d == 0 || m == 0 || m > 12 || d > getMaxDay( m, y ) ) { 
            cout << "\nThis is not a date!"; 
            return; 
        }
        vector<myTuple>::iterator f = find( holyday.begin(), holyday.end(), make_pair( d, m ) ); 
        int dd = d, day, wday, sea,  yr = y + 1166;
        for( int x = 1; x < m; x++ )
            dd += getMaxDay( x, 1 );
        day = dd % 73; if( !day ) day = 73; 
        wday = dd % 5; 
        sea  = ( dd - 1 ) / 73;
        if( d == 29 && m == 2 && isLeap( y ) ) { 
            cout << ( *f ).second() << " " << seasons[sea] << ", Year of Our Lady of Discord " << yr; 
            return; 
        }
        cout << wdays[wday] << " " << seasons[sea] << " " << day;
        if( day > 10 && day < 14 ) cout << "th"; 
        else switch( day % 10) { 
            case 1: cout << "st"; break; 
            case 2: cout << "nd"; break; 
            case 3: cout << "rd"; break; 
            default: cout << "th"; 
        }
        cout << ", Year of Our Lady of Discord " << yr;
        if( f != holyday.end() ) cout << " - " << ( *f ).second();
    }
private:
    int getMaxDay( int m, int y ) { 
        int dd[] = { 0, 31, isLeap( y ) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; return dd[m]; 
    }
    bool isLeap( int y ) { 
        bool l = false; 
        if( !( y % 4 ) ) { 
            if( y % 100 ) l = true; 
            else if( !( y % 400 ) ) l = true; 
        }
        return l; 
    }
    vector<myTuple> holyday; vector<string> seasons, wdays;
};
int main( int argc, char* argv[] ) {
    string date; discordian disc;
    while( true ) {
        cout << "Enter a date (dd mm yyyy) or 0 to quit: "; getline( cin, date ); if( date == "0" ) break;
        if( date.length() == 10 ) {
            istringstream iss( date ); 
            vector<string> vc;
            copy( istream_iterator<string>( iss ), istream_iterator<string>(), back_inserter<vector<string> >( vc ) );
            disc.convert( atoi( vc[0].c_str() ), atoi( vc[1].c_str() ), atoi( vc[2].c_str() ) ); 
            cout << "\n\n\n";
        } else cout << "\nIs this a date?!\n\n";
    }
    return 0;
}