24h購物| | PChome| 登入
2013-08-11 09:27:37| 人氣1,868| 回應0 | 上一篇 | 下一篇

[UVA][日期] 11947 - Cancer or Scorpio

推薦 0 收藏 0 轉貼0 訂閱站台



  F: Cancer or Scorpio 

Alice and Michael is a young couple who are planning on having their first child. Their wish their son Nelson was born on a special date for both of them.

Alice has investigated in the internet and has found that the period of gestation is forty weeks. These forty weeks begin to count on the first day of the last menstrual cycle.

Michael is passionate about astrology and even more about the zodiac signs, he has asked Alice to investigate the range of dates that correspond to each sign.


Sign Begin End
Aquarius January, 21 February, 19
Pisces February, 20 March, 20
Aries March, 21 April, 20
Taurus April, 21 May, 21
Gemini May, 22 June, 21
Cancer June, 22 July, 22
Leo July, 23 August, 21
Virgo August, 22 September, 23
Libra September, 24 October, 23
Scorpio October, 24 November, 22
Sagittarius November, 23 December, 22
Capricorn December, 23 January, 20


Alice and Michael ask for help to calculate the date of birth of their son Nelson and his zodiac sign.

Input 

The first line of input contains a single integer N, ( 1$ le$N$ le$1000) which is the number of datasets that follow.

Each dataset consists of a single line of input that contains only eight digits that represent the date of the first day of the last menstrual cycle in format MMDDYYYY.

Output 

For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, the date of birth in format MM/DD/YYYY, a space, and the name (in lowercase) of zodiac sign that correspond according to the date of birth.


Note: Considers leap years.

Sample Input 

2 
01232009 
01232008

Sample Output 

1 10/30/2009 scorpio 
2 10/29/2008 scorpio



計算懷孕 280 天後的日期,並且判斷是哪個星座。
在計算日期時,要考慮閏年。

#include <stdio.h>
#include <string.h>
void addDay(int &mm, int &dd, int &yy) {
    int m[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int leap = (yy%4 == 0 && yy%100 != 0 || yy%400 == 0);
    if(leap)    m[2]++;
    dd++;
    if(dd > m[mm])  mm++, dd = 1;
    if(mm == 13)
        yy++, dd = 1, mm = 1;
}
void zodiacSign(int mm, int dd) {
    if((mm == 1 && dd >= 21) || (mm == 2 && dd <= 19))
        puts("aquarius");
    else if((mm == 2 && dd >= 20) || (mm == 3 && dd <= 20))
        puts("pisces");
    else if((mm == 3 && dd >= 21) || (mm == 4 && dd <= 20))
        puts("aries");
    else if((mm == 4 && dd >= 21) || (mm == 5 && dd <= 21))
        puts("taurus");
    else if((mm == 5 && dd >= 22) || (mm == 6 && dd <= 21))
        puts("gemini");
    else if((mm == 6 && dd >= 22)  || (mm == 7 && dd <= 22))
        puts("cancer");
    else if((mm == 7 && dd >= 23) || (mm == 8 && dd <= 21))
        puts("leo");
    else if((mm == 8 && dd >= 22) || (mm == 9 && dd <= 23))
        puts("virgo");
    else if((mm == 9 && dd >= 23) || (mm == 10 && dd <= 23))
        puts("libra");
    else if((mm == 10 && dd >= 24) || (mm == 11 && dd <= 22))
        puts("scorpio");
    else if((mm == 11 && dd >= 23) || (mm == 12 && dd <= 22))
        puts("sagittarius");
    else
        puts("capricorn");
}
int main() {
    int testcase, cases = 0;
    int mm, dd, yy;
    int i;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%2d%2d%4d", &mm, &dd, &yy);
        for(i = 0; i < 280; i++)
            addDay(mm, dd, yy);
        printf("%d %02d/%02d/%04d ", ++cases, mm, dd, yy);
        zodiacSign(mm, dd);
    }
    return 0;
}

台長: Morris
人氣(1,868) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][日期] 12148 - Electricity
此分類上一篇:[UVA][dp] 10599 - Robots(II)

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文