AcWing 3370. 牛年
原题链接
简单
作者:
H.A.H.
,
2022-03-25 12:29:54
,
所有人可见
,
阅读 197
<< 轻点一下这里吧
$\Huge\color{green}{春季每日一题2022题解集合}$
C++ 代码
#include<bits/stdc++.h>
using namespace std;
map <string,int> name,year,ans;
int main(){
year["Rat"]=1;
year["Ox"]=2;
year["Tiger"]=3;
year["Rabbit"]=4;
year["Dragon"]=5;
year["Snake"]=6;
year["Horse"]=7;
year["Goat"]=8;
year["Monkey"]=9;
year["Rooster"]=10;
year["Dog"]=11;
year["Pig"]=12;
name["Bessie"]=2;
ans["Bessie"]=0;
int n;
cin>>n;
for(int i=1;i<=n;i++){
string st1,st2;
string name1,name2,year1,pn;
cin>>name1>>st1>>st1>>pn>>year1>>st2>>st2>>name2;
name[name1]=year[year1];
if(pn=="previous"){
if(year[year1]<name[name2]){
ans[name1]=ans[name2]-name[name2]+year[year1];
}else{
ans[name1]=ans[name2]-(name[name2]+12-year[year1]);
}
}else if(pn=="next"){
if(year[year1]>name[name2]){
ans[name1]=ans[name2]+year[year1]-name[name2];
}else{
ans[name1]=ans[name2]+12-name[name2]+year[year1];
}
}
}
cout<<abs(ans["Elsie"])<<endl;
return 0;
}