HDU-2005

来源:互联网 发布:java快速排序简单代码 编辑:程序博客网 时间:2024/05/21 23:39
#include<iostream>#include<string>using namespace std;int main(){string date;int daysOfMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};while(cin>>date){int year,month,day;string y,m,d;int sum=0;int pos1=0,pos2=0;for(int i=0;i<date.length();i++){if(date[i]=='/'){pos1=i;break;}}for(int i=0;i<date.length();i++){if(date[i]=='/'){pos2=i;}}y=date.substr(0,pos1);m=date.substr(pos1+1,pos2-pos1-1);d=date.substr(pos2+1);year = atoi(y.c_str());month = atoi(m.c_str());day = atoi(d.c_str());if( ( ( year%4 == 0) && (year%100 != 0)) || ( year%400 == 0) ){daysOfMonth[1]=29;}else{daysOfMonth[1]=28;}for(int i=0;i<month;i++){sum+=daysOfMonth[i];}sum=sum-(daysOfMonth[month-1]-day);cout<<sum<<endl;}return 0;}


总结:

1.代码基础不够扎实,花费较多时间研究字符串的用法完成解题

2.题意逻辑不够清楚表达,如:(year%100 != 0)这个条件漏写,导致3A

3.虽然3A但是起码是自己完成的啊,大水逼都是这样进化的


0 0
原创粉丝点击