hdu_2005_第几天?

来源:互联网 发布:linux开机自启动设置 编辑:程序博客网 时间:2024/06/09 17:06

http://acm.hdu.edu.cn/showproblem.php?pid=2005

第几天?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30000    Accepted Submission(s): 11576


Problem Description
给定一个日期,输出这个日期是该年的第几天。
 

Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
 

Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
 

Sample Input
1985/1/202006/3/12
 

Sample Output
2071
 
      1. #include<iostream>
      2. using namespace std;
      3. int main()
      4. {
      5. int y,m,d,outn,flog,i;
      6. char c;
      7. while(cin>>y>>c>>m>>c>>d)
      8. {
      9. if(m==1)
      10. outn=d;
      11. else if(m==2)
      12. outn=31+d;
      13. else if(m>2&&m<8)
      14. {
      15. outn=31+28+d;
      16. flog=1;
      17. for(i=3;i<m;i++)
      18. {
      19. if(flog>0)
      20. {
      21. outn+=31;
      22. flog=-flog;
      23. }
      24. else
      25. {
      26. outn+=30;
      27. flog=-flog;
      28. }
      29. }
      30. }
      31. else if(m>7&&m<13)
      32. {
      33. outn=31+28+31+30+31+30+31+d;
      34. flog=1;
      35. for(i=8;i<m;i++)
      36. {
      37. if(flog>0)
      38. {
      39. outn+=31;
      40. flog=-flog;
      41. }
      42. else
      43. {
      44. outn+=30;
      45. flog=-flog;
      46. }
      47. }
      48. }
      49. if(((y%4==0)&&(y%100!=0)||(y%400==0))&&m>2)
      50. outn+=1;
      51. cout<<outn<<endl;
      52. }
      53. return 0;
      54. }

原创粉丝点击