您的位置:首页 > 理论基础 > 计算机网络

HDU - 6213 Chinese Zodiac (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1008)

2017-09-17 20:10 591 查看



2017 ACM/ICPC Asia Regional Qingdao Online 1008


Chinese Zodiac

Problem Description

The Chinese Zodiac, known as Sheng Xiao, is based on a twelve-year cycle, each year in the cycle related to an animal sign. These signs are the rat, ox, tiger, rabbit, dragon, snake, horse, sheep, monkey, rooster, dog and pig.

Victoria is married to a younger man, but no one knows the real age difference between the couple. The good news is that she told us their Chinese Zodiac signs. Their years of birth in luner calendar is not the same. Here we can guess a very rough estimate
of the minimum age difference between them.

If, for instance, the signs of Victoria and her husband are ox and rabbit respectively, the estimate should be 2 years.
But if the signs of the couple is the same, the answer should be 12 years.

 

Input

The first line of input contains an integer T (1≤T≤1000) indicating
the number of test cases.

For each test case a line of two strings describes the signs of Victoria and her husband.

 

Output

For each test case output an integer in a line.

 

Sample Input

3
ox rooster
rooster ox
dragon dragon

 

Sample Output

8
4
12

 

Source

2017 ACM/ICPC Asia Regional Qingdao Online

 

#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
using namespace std;

int T;
char buf[50],buf2[50];
int diff(int x){return (x>=0?x:-x);}
int retr(char* buf){
if(strcmp(buf,"rat")==0)return 1;
else if(strcmp(buf,"ox")==0)return 2;
else if(strcmp(buf,"tiger")==0)return 3;
else if(strcmp(buf,"rabbit")==0)return 4;
else if(strcmp(buf,"dragon")==0)return 5;
else if(strcmp(buf,"snake")==0)return 6;
else if(strcmp(buf,"horse")==0)return 7;
else if(strcmp(buf,"sheep")==0)return 8;
else if(strcmp(buf,"monkey")==0)return 9;
else if(strcmp(buf,"rooster")==0)return 10;
else if(strcmp(buf,"dog")==0)return 11;
else if(strcmp(buf,"pig")==0)return 12;
}
int main(){
scanf("%d",&T);
int res;
while(T--){
scanf("%s",buf);
scanf("%s",buf2);
if(retr(buf)==retr(buf2)){
res = 12;
}else if(retr(buf)>retr(buf2)){
res = 12-retr(buf)+retr(buf2);
}else {
res = retr(buf2)-retr(buf);
}

printf("%d\n",res);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐