標籤:ace tput sub 轉化 result code main mission 資料格式
第幾天?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 181543 Accepted Submission(s): 64444
Problem Description給定一個日期,輸出這個日期是該年的第幾天。
Input輸入資料有多組,每組佔一行,資料格式為YYYY/MM/DD組成,具體參見sample input ,另外,可以向你確保所有的輸入資料是合法的。
Output對於每組輸入資料,輸出一行,表示該日期是該年的第幾天。
Sample Input1985/1/202006/3/12
Sample Output2071
1 #include<string.h> 2 #include<cstdio> 3 #include<stdlib.h> 4 using namespace std; 5 int main() 6 { 7 char s[100]; 8 int time[3]; 9 char * p;10 11 12 while(scanf("%s",s)!=EOF)13 {14 int result = 0;15 int count = 0;16 int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};17 p = strtok(s,"/");//s為要拆分的字串,必須是char *類型,""裡是分隔字元,可以" */#"等18 while(p != NULL)//拆分字串19 {20 time[count++] = atoi(p);//將字串轉化為整型21 p = strtok(NULL,"/");22 }23 if(time[0]%400 == 0 || ( time[0]%4==0 && time[0]%100!=0 ))24 {25 month[2] = 29;26 }27 for(int i = 1;i < time[1];++i)28 {29 result += month[i];30 }31 result += time[2];32 printf("%d\n",result);33 34 }35 return 0;36 }
hdu2005 第幾天?【C++】