[HDU-6213]Chinese Zodiac

Chinese Zodiac

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2306 Accepted Submission(s): 1379

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

Answer

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int num = 0;
        Scanner sc = new Scanner(System.in);
        num = sc.nextInt();
        String Zodiac[] = {"rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep", "monkey", "rooster", "dog", "pig"};
        while (num != 0) {
            String s1 = sc.next();
            int i1 = 0;
            int i2 = 0;
            for (int i = 0; i < 12; i++) {
                if (s1.equals(Zodiac[i])) {
                    i1 = i + 1;
                    break;
                }
            }
            String s2 = sc.next();
            for (int i = 0; i < 12; i++) {
                if (s2.equals(Zodiac[i])) {
                    i2 = i + 1;
                    break;
                }
            }
            if (i1 < i2) {
                System.out.println(i2 - i1);
            } else if (i1 > i2) {
                System.out.println(12 - i1 + i2);
            } else
                System.out.println("12");
            num--;
        }
    }
}
发布了65 篇原创文章 · 获赞 26 · 访问量 2917

猜你喜欢

转载自blog.csdn.net/weixin_43332735/article/details/104782517