UVa 11947
来源:互联网 发布:三层网络结构 编辑:程序博客网 时间:2024/05/16 19:20
题目:计算孩子出生的日期以及对应的星座,已知最后经期的日期,预产期是它后面的第四周(280天)。
分析:模拟。按照要求求出280天后的日期和对应的星座。
需要注意:1.闰年;
2.计算结果会跨年,也要判断是不是闰年;
说明:注意输出的月份和日期是两位,不足补零。
#include <stdio.h>#include <stdlib.h>int get_number(char str[], int s, int e){int value = 0;for (int i = s; i <= e; ++ i) {value = value*10 + str[i]-'0';}return value;}int days_of_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int zodiac_bound[13] = {0, 21, 20, 21, 21, 22, 22, 23, 22, 24, 24, 23, 23};char zodiac_name[13][13] = {"capricorn", "aquarius", "pisces", "aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn"};int main(){int n;char buf[10];while (~scanf("%d",&n)) for (int i = 1; i <= n; ++ i) {scanf("%s",buf);int month = get_number(buf, 0, 1);int day = get_number(buf, 2, 3);int year = get_number(buf, 4, 7);// leap yeardays_of_month[2] = 28 + (year%4 == 0 && year%100 || year%400 == 0);day += 280;while (day > days_of_month[month]) {day -= days_of_month[month];month ++;// int next yearif (month > 12) {month = 1;year ++;// leap yeardays_of_month[2] = 28 + (year%4 == 0 && year%100 || year%400 == 0);}}printf("%d %02d/%02d/%04d ",i,month,day,year);if (day < zodiac_bound[month]) {printf("%s\n",zodiac_name[month-1]);}else {printf("%s\n",zodiac_name[month]);}}return 0;}
阅读全文
0 0
- UVa 11947
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 画布做加载动画!
- 矩形嵌套(经典dp)
- mysql 查看字符集, 更改字符集
- bzoj 1801: [Ahoi2009]chess 中国象棋
- 鼠标点击某处, 让精灵移动到该处 (如下图) 鼠标移动时, 让精灵跟随鼠标移动
- UVa 11947
- shell编程
- solr搭建
- codeforces 828A Restaurant Tables
- Bigtable: A Distributed Storage System for Structured Data : part1 Abstract and Introduction
- MySQL之操作数据表
- 使用宏定义计算函数实参个数
- 小试ffplay+MFC
- mybatis的注解