描述

One day, boy A and girl B are playing a dice game. First, they write a number between 1~6 in a piece of paper, and then roll the dice. The one whose number is closer to the number of the dice will win this game. For example, A wins if |a-x|<|b-x|. And |a-x|=|b-x| means a draw.

输入

Each test case cantains two integers a and b, representing the numbers guessed by boy A and girl B respectively. The input is terminated in the end of file (EOF).

输出

For each test case, you must print the numbers of the cases of "A wins", "draw" and "B wins".

输入样例 1

2 5

输出样例 1

3 0 3

输入样例 2

2 4

输出样例 2

2 1 3

思路:

第一节课学的是暴力,所以遍历1~6,然后比较每个数与输入的数的绝对值之间的大小,用三个变量来记录赢的情况和平局情况,有一小点可以改进的就是这三个数相加一定是6,所以B赢的次数可以用6来减去A赢的次数和平局次数,就不用else多次判断了。

#include<iostream>
#include<bits/stdc++.h>
using namespace std;int main()
{int a, b;while (cin >> a && cin >> b){int awin = 0, bwin = 0, draw = 0;for (int i = 1; i <= 6; i++){if (abs(a - i) < abs(b - i))awin++;else if (abs(a - i) == abs(b - i))draw++;}bwin = 6 - awin - draw;cout << awin << " " << draw << " " << bwin << endl;}return 0;
}

北林oj-算法设计与分析-A dice game(思路+代码)相关推荐

  1. 北林oj-算法设计与分析-Removing the Wall(C++,思路+代码)

    描述 There is a wall in Tom's garden, which is builded by N different bricks. Bricks may have differen ...

  2. 北林oj-算法设计与分析-Simple Count(C++,思路+代码)

    描述 Count how many numbers do not contain 4 or 7 in the N numbers from 1 to N. 输入 Each test case star ...

  3. 北林oj-算法设计与分析-Tom palindrome number

    描述 Tom is studing math these days. If there is a number X, whose binary form and decimal form are al ...

  4. 北林oj-算法设计与分析-Don‘t touch my cake(题意+代码)

    描述 A boy bought N different cakes someday. They were arranged randomly in a line given by permutatio ...

  5. 北林oj-算法设计与分析-Line up in the canteen(两种解法,附思路)

    描述 One day, there is a kind of new delicious food from one of the windows in the canteen. All studen ...

  6. 【算法设计与分析】经典常考三十三道例题AC代码

    ❥小虾目前大三,我校在大一下开设<数据结构>这门课,大二上开了<算法设计与分析>这门课,很庆幸这两门课的上机考试总成绩一门100,一门99,最后总分也都90+.下文会给出机试的 ...

  7. C++ 算法设计与分析 地图着色问题(中国+美国)

    文章目录 中国+美国可选择地图着色问题 地图着色问题 解决方法 回溯法 队列 代码展示 美国地图着色 代码(c++) 结果 中国+美国地图着色 代码(c++) 结果 可视化 中国+美国可选择地图着色问 ...

  8. 【算法设计与分析】屈婉玲教授—课程笔记

    网课地址与课件 B站:[北大公开课] 算法设计与分析 屈婉玲教授 (76p) 课件:来源于评论区小伙伴分享(百度云)     提取码:1111 笔记 课程知识框架 算法设计思想 设计思想:尽量选复杂度 ...

  9. 算法设计与分析(屈婉玲)网络课学习笔记(一)

    2017.10.10 21:47 放一波课程的链接首先:http://www.chinesemooc.org/live/685712    华文慕课 北京大学屈婉玲女神的视频教程,非常推荐  学习算法 ...

最新文章

  1. 玩转HTML5移动页面
  2. 数据结构与算法(C++)– 动态规划(Dynamic Programming)
  3. 融合通信常见问题3月刊 | 云信小课堂
  4. mac php 怎么启动命令,Mac 使用homebrew启动PHP环境命令
  5. 《DSP using MATLAB》Problem 7.2
  6. mogodbshell中数组对象查询修改方法
  7. coverity代码检测工具介绍_微服务测试之静态代码扫描
  8. mybatis学习(19):模糊查询#
  9. mysql datetime不支持小数_如何从python向MYSQL中插入空小数/datetime?
  10. 打开d盘由于这台计算机的限制,又出现限制我想打开D盘、E盘,就是打不开,电脑提示:限制本 爱问知识人...
  11. sap ABAP中常用函数
  12. Linux kernel kfifo分析【转】
  13. Win32程序和控制台应用程序的项目互转设置
  14. LeNet的详细网络结构
  15. FreeSWITCH channel variables(信道变量)
  16. XML 转 JSON
  17. 彻底解决pycharm中用matplotlib表格绘制时图表中汉字设置
  18. 人类的历史就是一部创业史
  19. uWSGI和Gunicorn
  20. python基本操作_python的基本操作

热门文章

  1. linux部署多个jar 会宕机_部署springboot+vue项目文档(若依ruoyi项目部署步骤)
  2. 从零开始实现数据结构(一) 动态数组
  3. 实现多线程爬取数据并保存到mongodb
  4. nodejs mac启动相关命令
  5. 人月神话阅读笔记之二
  6. flutter Radio 单选框
  7. TMS320VC5509片内ADC采集
  8. 第六篇:视图、触发器、事务、存储过程、函数
  9. 10月21日下午PHP常用函数
  10. java枚举类型转换为Struts2的select的数据