题目描述
已知 1900年是鼠年,输入一个年份,输出其对应生肖。
鼠 rat 牛 ox 虎 tiger 兔 rabbit 龙 dragon 蛇 snake
马 horse 羊 sheep 猴 monkey 鸡 rooster 狗 dog 猪 pig
输入
输入一个整数 year 表示年份(1≤year≤9999)。
输出
输出一个单词,表示生肖。
样例输入 Copy
1900
样例输出 Copy
rat
代码实现:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
int main()
{
//鼠 rat 牛 ox 虎 tiger 兔 rabbit 龙 dragon 蛇 snake
//马 horse 羊 sheep 猴 monkey 鸡 rooster 狗 dog 猪 pig
ios::sync_with_stdio;
cin.tie(0);
cout.tie(0);
int year;
cin>>year;
if(year>=1900)
{
int ans=(year-1900)%12;
if(ans==0)
{
cout<<"rat";
}
if(ans==1)
{
cout<<"ox";
}
if(ans==2)
{
cout<<"tiger";
}
if(ans==3)
{
cout<<"rabbit";
}
if(ans==4)
{
cout<<"dragon";
}
if(ans==5)
{
cout<<"snake";
}
if(ans==6)
{
cout<<"horse";
}
if(ans==7)
{
cout<<"sheep";
}
if(ans==8)
{
cout<<"monkey";
}
if(ans==9)
{
cout<<"rooster";
}
if(ans==10)
{
cout<<"dog";
}
if(ans==11)
{
cout<<"pig";
}
}
else if(year<1900)
{
int an=(1900-year)%12;
if(an==0)
{
cout<<"rat";
}
if(an==11)
{
cout<<"ox";
}
if(an==10)
{
cout<<"tiger";
}
if(an==9)
{
cout<<"rabbit";
}
if(an==8)
{
cout<<"dragon";
}
if(an==7)
{
cout<<"snake";
}
if(an==6)
{
cout<<"horse";
}
if(an==5)
{
cout<<"sheep";
}
if(an==4)
{
cout<<"monkey";
}
if(an==3)
{
cout<<"rooster";
}
if(an==2)
{
cout<<"dog";
}
if(an==1)
{
cout<<"pig";
}
}
return 0;
}