题目大意:

输入两个人的属相,并且第一个人一定比第二个人岁数大,问你这两个人至少差多少岁。

代码:

#include<bits/stdc++.h>
using namespace std;
//rat, ox, tiger, rabbit, dragon, snake, horse, sheep, monkey, rooster, dog and pig.
int f(char *s)
{
    if(s[0]=='r'&&s[1]=='a'&&s[2]=='t')return 1;
    if(s[0]=='o')return 2;
    if(s[0]=='t')return 3;
    if(s[0]=='r'&&s[1]=='a'&&s[2]=='b')return 4;
    if(s[0]=='d'&&s[1]=='r')return 5;
    if(s[0]=='s'&&s[1]=='n')return 6;
    if(s[0]=='h')return 7;
    if(s[0]=='s'&&s[1]=='h')return 8;
    if(s[0]=='m')return 9;
    if(s[0]=='r'&&s[1]=='o')return 10;
    if(s[0]=='d'&&s[1]=='o')return 11;
    return 12;
}
char a[1000],b[1000];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s%s",a,b);
        int aa=f(a);int bb=f(b);
        int ans;
        if(aa-bb>0)ans=12-(aa-bb);
        else if(aa-bb<0)ans=bb-aa;
        else ans=12;
        printf("%d\n",ans);
    }

}