首页 > 代码库 > 2014华为实习上级笔试题——三天打鱼两天晒网
2014华为实习上级笔试题——三天打鱼两天晒网
#include<iostream>
using namespace std;
int func(int year)//判断闰年的个数
{
int count=0;
for(int i=1990;i<year;i++)
if(year%4==0&&year%100!=0||year%400==0)
count++;
return count;
}
int main()
{
int year,month,day;
int count,sum,num;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//把08 09 转化为8 9
char a[2],b[2];
cin>>year;
cin>>a[0]>>a[1];
cin>>b[0]>>b[1];
if(a[0]==‘0‘)
month=a[1]-‘0‘;
else month=(a[0]-‘0‘)*10+a[1]-‘0‘;
if(b[0]==‘0‘)
day=b[1]-‘0‘;
else day=(b[0]-‘0‘)*10+b[1]-‘0‘;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
count=func(year);
switch(month)
{
case 1:
num=0;
break;
case 2:
num=31;
break;
case 3:
num=59;
break;
case 4:
num=90;
break;
case 5:
num=120;
break;
case 6:
num=151;
break;
case 7:
num=181;
break;
case 8:
num=212;
break;
case 9:
num=243;
break;
case 10:
num=273;
break;
case 11:
num=304;
break;
case 12:
num=334;
break;
default:
break;
}
if((year%4==0&&year%100!=0||year%400==0)&&month>2)
num=num+1;
sum=(year-1990)*365+count+num+day;
if(sum%5>=1&&sum%5<=3)
cout<<"Fishing"<<endl;
else cout<<"Sleeping"<<endl;
return 0;
}
using namespace std;
int func(int year)//判断闰年的个数
{
int count=0;
for(int i=1990;i<year;i++)
if(year%4==0&&year%100!=0||year%400==0)
count++;
return count;
}
int main()
{
int year,month,day;
int count,sum,num;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//把08 09 转化为8 9
char a[2],b[2];
cin>>year;
cin>>a[0]>>a[1];
cin>>b[0]>>b[1];
if(a[0]==‘0‘)
month=a[1]-‘0‘;
else month=(a[0]-‘0‘)*10+a[1]-‘0‘;
if(b[0]==‘0‘)
day=b[1]-‘0‘;
else day=(b[0]-‘0‘)*10+b[1]-‘0‘;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
count=func(year);
switch(month)
{
case 1:
num=0;
break;
case 2:
num=31;
break;
case 3:
num=59;
break;
case 4:
num=90;
break;
case 5:
num=120;
break;
case 6:
num=151;
break;
case 7:
num=181;
break;
case 8:
num=212;
break;
case 9:
num=243;
break;
case 10:
num=273;
break;
case 11:
num=304;
break;
case 12:
num=334;
break;
default:
break;
}
if((year%4==0&&year%100!=0||year%400==0)&&month>2)
num=num+1;
sum=(year-1990)*365+count+num+day;
if(sum%5>=1&&sum%5<=3)
cout<<"Fishing"<<endl;
else cout<<"Sleeping"<<endl;
return 0;
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。