UVa: 11947 (Cancer or Scorpio)


Input:
2
04230004
04232004

Accepted Output:
1 01/28/0005 aquarius
2 01/28/2005 aquarius


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <ctime>

#define Inf 2147483647
#define Pi acos(-1.0)
#define N 1000000
#define LL long long
#define F(i, n) for( int i = (0); i < (n); i++ )
#define Fs(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Set(a, s) memset(a, s, sizeof (a))
inline LL Power(int b, int p) { LL r = 1; for ( int i = 1; i <= p; i++ ) r *= b; return r; }

using namespace std;

int dayInMonths [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool isLeapYear(int year) {
    if (year % 400 == 0) return true;
    if (year % 100 == 0) return false;
    if (year % 4 == 0) return true;
    return false;
}


int countDays(int day, int month, int year) {

    int counter = 0;

    for ( int i = 1; i < year; i++ ) {
        counter += (isLeapYear(i) ? 366 : 365);
    }

    for ( int i = 1; i < month; i++ ) {
        counter += dayInMonths [i - 1];
    }

    counter += day;

    if (month > 2 && isLeapYear(year)) counter++;

    return counter;
}

void printZodiacSign(int date, int month) {

    struct node {
        char const *sign;
        int startMonth;
        int startDate;
        int endMonth;
        int endDate;

        node () {}

        node(char const *s, int a, int b, int c, int d) {
            this->sign = s;
            this->startMonth = a;
            this->startDate = b;
            this->endMonth = c;
            this->endDate = d;
        }
    } n [12];

    n [0] = node("aquarius", 1, 21, 2, 19);
    n [1] = node("pisces", 2, 20, 3, 20);
    n [2] = node("aries", 3, 21, 4, 20);
    n [3] = node("taurus", 4, 21, 5, 21);
    n [4] = node("gemini", 5, 22, 6, 21);
    n [5] = node("cancer", 6, 22, 7, 22);
    n [6] = node("leo", 7, 23, 8, 21);
    n [7] = node("virgo", 8, 22, 9, 23);
    n [8] = node("libra", 9, 24, 10, 23);
    n [9] = node("scorpio", 10, 24, 11, 22);
    n [10] = node("sagittarius", 11, 23, 12, 22);
    n [11] = node("capricorn", 12, 23, 1, 20);

    for ( int i = 0; i < 12; i++ ) {
        if (month == n [i].startMonth) {
            if (date >= n [i].startDate) { printf ("%s\n", n [i].sign); break; }

        } else if (month == n [i].endMonth) {
            if (date <= n [i].endDate) { printf ("%s\n", n [i].sign); break; }
        }
    }
}

void printOutput(int days) {

    int year = 1;
    int month = 1;

    while(days >= 365) {
        days -= (isLeapYear(year) ? 366 : 365);

        if (days <= 0) {
            days += (isLeapYear(year) ? 366 : 365);
            break;
        }

        year++;
    }

    if (days) {

        if (isLeapYear(year)) dayInMonths [1]++;

        while (days > dayInMonths [month - 1]) {
            days -= dayInMonths [month - 1];
            month++;
        }
    }

    printf ("%02d/%02d/%04d ", month, days, year);

    printZodiacSign(days, month);

}

int digit(char c) {
    return c - 48;
}


int main ()
{
    int testCases;

    scanf ("%d", &testCases);

    int cases = 0;

    while (testCases--) {
        char input [8 + 10];
        scanf ("%s", input);

        dayInMonths [1] = 28;

        int totalNumberOfDays = countDays(digit (input [2]) * 10 + digit (input [3]),
                digit (input [0]) * 10 + digit (input [1]),
                digit (input [4]) * 1000 + digit (input [5]) * 100 + digit (input [6]) * 10 + digit (input [7]));

        printf ("%d ", ++cases);

        printOutput(totalNumberOfDays + 40 * 7);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s