• HDU 6213 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 (1T1000) 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
     

    【题意】:一个女的找了一个比自己小的丈夫,没有人知道他们的年领差,但是知道他们的十二生肖。问女的至少比男的大多少岁。

    【分析】如果两人属相相同,肯定大一轮,就是12.

    如果女的属相比男的靠后,则就是12-(女的属相-男的属相)

    如果女的属相比男的靠前,则就是(男的属相-女的属相)

    【代码】:

    15MS 1948K
    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<map>
    #include<set>
    #include<string>
    using namespace std;
    
    int main()
    {
        int t;
        string f,m;
        cin>>t;
        map<string,int> mp;
    /*rat, ox, tiger, rabbit, dragon, snake, horse, sheep, monkey, rooster, dog and pig.*/
        while(t--)
        {
            cin>>f>>m;
            mp["rat"]=1;
            mp["ox"]=2;
            mp["tiger"]=3;
            mp["rabbit"]=4;
            mp["dragon"]=5;
            mp["snake"]=6;
            mp["horse"]=7;
            mp["sheep"]=8;
            mp["monkey"]=9;
            mp["rooster"]=10;
            mp["dog"]=11;
            mp[" pig"]=12;
            if(mp[f]==mp[m]) cout<<12<<endl;
            else if(mp[f]<mp[m]) cout<<abs(mp[f]-mp[m])<<endl;
            else cout<<12-abs(mp[f]-mp[m])<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    UIView动画设置
    窗口与视图的基本概念
    OC基本框架之-字典类型
    将博客搬至CSDN
    objective-c中的深、浅拷贝
    基础算法之二分法查找
    C语言中格式字符指定输出项的数据类型和输出格式总结
    JavaScript学习笔记(9)——JavaScript语法之流程控制
    JavaScript学习笔记(8)——JavaScript语法之运算符
    JavaScript学习笔记(7)——JavaScript语法之函数
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7538360.html
Copyright © 2020-2023  润新知