C语言趣味例题
三天打鱼两天晒网问题
1 #include <iostream> 2 using namespace std; 3 class Date{ 4 public: 5 int year,month,day; 6 Date(int y,int m,int d):year(y),month(m),day(d){ 7 } 8 }; 9 bool runyear(int x) 10 { 11 if((x%400==0) || (x%4==0 && x%100!=0)) 12 { 13 return true; 14 } 15 else 16 { 17 return false; 18 } 19 } 20 int count(class Date c) 21 { 22 int total=0; 23 int permonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 24 for(int year=1990;year<c.year;year++) 25 { 26 if(runyear(year)) 27 { 28 total+=366; 29 } 30 else 31 { 32 total+=365; 33 } 34 } 35 if(runyear(c.year)) 36 { 37 permonth[2]+=1; 38 } 39 for(int month=0;month<c.month;month++) 40 { 41 total+=permonth[month]; 42 } 43 total+=c.day; 44 return total%5; 45 } 46 int main() 47 { 48 int y,m,d; 49 cin>>y>>m>>d; 50 Date c(y,m,d); 51 if(count(c)==4 || count(c)==0) 52 { 53 cout<<"shaiwang"<<endl; 54 } 55 else 56 { 57 cout<<"dayu"<<endl; 58 } 59 return 0; 60 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?