c/c++语言开发共享万年历

“题目描述” 实现思路 “利用蔡勒公式计算” 代码实现 include include include using namespace std; int main() { string input; cin input; int first_=input.find(” “);//第一次出现” “的位 …


万年历

实现思路

利用蔡勒公式计算

代码实现

#include <iostream> #include <cstdlib> #include<cmath> using namespace std; int main() {     string input;     cin>>input;     int first_=input.find("-");//第一次出现"-"的位置.     int last_=input.rfind("-");//最后一次出现"-"的位置.     //cout<<first_<<endl;     //cout<<last_;     int year = atoi(input.substr(0,4).c_str());//取出年份     int month= atoi(input.substr(first_+1,last_-first_-1).c_str());//取出月份     int day = atoi(input.substr(last_+1).c_str());//取出天数     //cout<<year<<endl;     //cout<<month<<endl;     //cout<<day;     //利用蔡勒公式计算     if(month==1||month==2){         month=month+12;//1月份相当于上一年的13月,2月份相当于上一年的14月         year=year-1;     }     int c=year/100;//取年份的前两位数     int y=year%100;//取年份的后两位数     int m=month;     int d=day;     int w=int((y+floor(y/4)+floor(c/4)-2*c+floor(26*(m+1)/10)+d-1))%7;     if(w<0){         w=w+7;     }     switch(w){     case 0:         cout<<"sunday";         break;     case 1:         cout<<"monday";         break;     case 2:         cout<<"tuesday";         break;     case 3:         cout<<"wednesday";         break;     case 4:         cout<<"thursday";         break;     case 5:         cout<<"friday";         break;     case 6:         cout<<"saturday";         break;     }     return 0; }

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/606268.html

(0)
上一篇 2021年5月13日
下一篇 2021年5月13日

精彩推荐