120. 日期

博客要求计算第X年Y月Z日是第X年的第几天,需考虑闰年影响。给出输入格式,第一行整数T表示数据组数,后续每行是X:Y:Z格式字符串。还给出输出格式及输入输出样例。

请你计算出第X年Y月Z日是第X年的第几天。其中,1月1日是第一天,1月2日是第二天,以此类推。 
计算时请注意闰年的影响。对于非整百年,年数能整除4是闰年,否则不是闰年;对于整百年,年数能整除400是闰年,否则不是闰年。如1900年和1901年不是闰年,而2000年和2004年是闰年。 
输入格式 
第一行有一个整数T (T≤100),表示一共有T组数据需要你处理。 
接下来一共有T行,每行是一个如下格式的字符串:X:Y:Z,表示你需要计算第X年Y月Z日是第X年的第几天。其中X是一个大于0,小于2100的整数。保证字符串的格式都是合法的,字符串所表示的日期也都是存在的。

输出格式 
对于每组数据,你需要输出一个整数,表示所求得的结果。

输入样例 

2013:4:12 
112:4:12 
输出样例 
102 
103
 

#include <cstdio>
#include <iostream>
using namespace std;
int judge(int n)
{
    if((n%4==0&&n%100!=0) || n%400==0 )
        return 1;
    return 0;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int y,m,d;
        int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        scanf("%d:%d:%d",&y,&m,&d);
        if(judge(y))
            month[2] =29;
        int sum=0;
        for(int i=1; i < m; i++)
        {
            sum+=month[i];
        }
        sum+=d;
        printf("%d\n",sum);
    }
    return 0;
}

 

期末作业要求如下: Write a program that will help elementary school pupils practice math. a) The program will first ask the user for his/her ID number (including two letters & 4 digits), e.g. Please input your four digit ID no: AB1234 The program should have input validation. Then the program prompts three choices: (1) Start a test (2) Check scores (3) Exit Test: the program will give 10 math problems, e.g.: 12 * 3 = 36 48 + 32 = 80 … 56 / 28 = 2 Note: i) Pupils will answer each problem before the next one is given. ii) The problems should include addition, subtraction, multiplication and division. They are randomly generated. iii) Randomly generates numbers for problems. However, must ensure that both the problem and the result are no larger than two digits. The problem and the result should be greater than or equal to zero. The divisor cannot be zero. iv) After ten problems are finished, record the time used by the student to do the ten problems. v) Gives a score to each student. Saves this student’s ID, his/her score and the time used into a file named ‘record.txt’. vi) Print the following information on the screen: Prob. | Correct Answ. | Ur Answ c) Check scores: Searches the file ‘record.txt’ and lists all the historical scores for this student, e.g.: Your previous records are: AB1234 80 150 seconds AB1234 50 182 seconds AB1234 90 98 seconds You will be marked based on your program’s: (1) Correctiveness (2) Readability (3) Robustness (4) Conciseness 目前本人的程序可以直接使用,并完全满足要求。还是建议学弟学妹在字里行间多多理解,争取自己写出漂亮的代码! 向本人在完成此作业过程中参考的代码表示衷心的感谢!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值