hdu2005 第幾天?【C++】

來源:互聯網
上載者:User

標籤: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++】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.