博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu6213 Chinese Zodiac
阅读量:4156 次
发布时间:2019-05-26

本文共 1982 字,大约阅读时间需要 6 分钟。

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
3ox roosterrooster oxdragon dragon
Sample Output
8412
题目大意:

一个年长的女人要和一个帅气的年轻人结婚, 两个人的年龄差不超过12岁。我们只能够根据两人出生年份的生肖,来得到两人的年龄差。

我的做法:

先用一个字符串数组存储十二生肖,然后根据两人出生年份的生肖得到一个年龄差。

样例一:直接rooster - ox,得8

样例二:ox + 12 - rooster,得4(女人的年龄大,即rooster表示的年份小一些)

样例三:dragon - dragon == 0, 直接输出12

通过一个mod12把三种情况统一起来,即:(男人生肖 + 12 - 女人生肖) % 12,若结果为0输出12。

AC代码:

#include 
#include
#include
using namespace std;int main(){ string zodiac[15] = {"rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep", "monkey", "rooster", "dog", "pig"}; int t; cin >> t; while(t--) { string a, b; int aint = 0, bint = 0; cin >> a >> b; for(int i = 0; i < 12; i++) { if(a == zodiac[i]) aint = i + 1; //数组0开始 if(b == zodiac[i]) bint = i + 1; } int ans = (bint + 12 - aint) % 12; //把样例ox rooster 和 rooster ox的情况一起处理了 printf("%d\n", ans ? ans : 12); } return 0;}

转载地址:http://inkxi.baihongyu.com/

你可能感兴趣的文章
python调试技巧
查看>>
这些年的项目管理心得
查看>>
使用 PHP 直接在共享内存中存储数据集
查看>>
替代netstat ss ip
查看>>
浅谈PHP代码设计结构
查看>>
谁贪占了我的系统资源 php-fpm
查看>>
eAccelerator 配置参数详解
查看>>
Redis中7种集合类型应用场景
查看>>
PHP5.2和PHP5.3的垃圾回收机制
查看>>
vim编辑二进制文件
查看>>
阻塞与非阻塞的区别
查看>>
ruby gem 国内镜像。。。 顶一下taobao
查看>>
安装ruby on rails & redmine管理软件
查看>>
mysql在已有无分区表增加分区,mysql5.5才有,可以是innodb_file_per_table关闭状态.
查看>>
Sed
查看>>
read 管道 子shell 无法赋值问题的解决
查看>>
python 代码 性能优化技巧
查看>>
PhantomJS 服务端渲染网页,记录各个请求信息
查看>>
多版本并发控制(MVCC)在分布式系统中的应用
查看>>
MySQL Partition扫盲
查看>>