标签:desc pre find ott bottom ace i++ int return
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 147067 Accepted Submission(s): 52729
#include <iostream> #include <string> #include <stdlib.h> using namespace std; int isLeapYear(int year) { if(year % 4 == 0 && year % 100 != 0 || year % 400 ==0) { return 29; } else { return 28; } } int monthToDay(int month,int year) { int day; switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: day = 31;break; case 4: case 6: case 9: case 11: day = 30;break; case 2: day = isLeapYear(year); } return day; } int main() { string date; while(cin>>date) { int year; int month; int day; int days = 0; int first = date.find(‘/‘, 0); int second = date.find(‘/‘, 5); int length = date.length(); year = atoi(date.substr(0, first).c_str()); month = atoi(date.substr(first + 1, second - first).c_str()); day = atoi(date.substr(second + 1, length - second).c_str()); for(int i = 1; i < month; i++) { days += monthToDay(i, year); } days += day; cout<<days<<endl; } return 0; }
JAVA撸多了,思路都不一样。。
标签:desc pre find ott bottom ace i++ int return
原文地址:http://www.cnblogs.com/hu81966/p/6698360.html