文章
25
粉丝
40
获赞
3
访问
20.5k
// time: 28mins
// scanf出问题没读进去, 初始化值没考虑充分, 判据少了一个 , 调试还是坏的
#include <iostream>
using namespace std;
struct date{
int year;
int month;
int day;
}p;
int arr[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool isLeap(int year){
if((year%4==0&&year%100!=0)||(year%400==0)) return true;
else return false;
}
int main(){
bool ju = true;
int sum;
// while(scanf("%d %d %d",p.year,p.month,p.day) != EOF){
while(cin>>p.year>>p.month>>p.day){
//多次输入中,多次对相关改动数据的初始化
//求和值,判据,数组改动
sum = 0; ju = true; arr[2] = 28;
if(p.year<=0) ju = false;
if(p.month<1||p.month>12) ju = false;
if(p.day<1||p.day>31) ju = false;
//细节判据
if(p.day>arr[p.month]) ju = false;
if(!ju) {
cout<<"Input error!"<<endl;
continue;
}
if(isLeap(p.year)) arr[2] = 29;
for(int i = 1;i<p.month;i++){
sum += arr[i];
}
sum += p.day;
cout<<sum<<endl;...
登录后发布评论
暂无评论,来抢沙发