当前位置:网站首页>L1-019 谁先倒(Lua)
L1-019 谁先倒(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就输了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。
下面给出甲、乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒。
输入格式:
输入第一行先后给出甲、乙两人的酒量(不超过100的非负整数),以空格分隔。下一行给出一个正整数N(≤100),随后N行,每行给出一轮划拳的记录,格式为:
甲喊 甲划 乙喊 乙划
其中喊是喊出的数字,划是划出的数字,均为不超过100的正整数(两只手一起划)。
输出格式:
在第一行中输出先倒下的那个人:A代表甲,B代表乙。第二行中输出没倒的那个人喝了多少杯。题目保证有一个人倒下。注意程序处理到有人倒下就终止,后面的数据不必处理。
输入样例:
1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16
输出样例:
A
1
代码
function ReadValue(str)
local arr = {
}
local idx = 1
for i = 1, #str do
if str:sub(i,i) == " " then
table.insert(arr, tonumber(str:sub(idx, i - 1)))
idx = i + 1
end
end
table.insert(arr, tonumber(str:sub(idx)))
return arr[1], arr[2], arr[3], arr[4]
end
local str = io.read()
local x1, x2 = 0, 0
for i = 1, #str do
if str:sub(i,i) == " " then
x1 = tonumber(str:sub(1, i - 1))
x2 = tonumber(str:sub(i + 1))
break
end
end
local n = io.read()
local d1, d2 = 0, 0
for i = 1, n do
local a1, a2, b1, b2 = ReadValue(io.read())
local ans = a1 + b1
if a2 == ans and b2 ~= ans then
d1 = d1 + 1
else
if a2 ~= ans and b2 == ans then
d2 = d2 + 1
end
end
if d1 > x1 then
print("A")
print(d2)
break
end
if d2 > x2 then
print("B")
print(d1)
break
end
end
边栏推荐
- Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
- Shallow understanding Net core routing
- Pycharm IDE下载
- Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
- Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
- QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
- 服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
- User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- Seaborn data visualization
猜你喜欢
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
DevOps 的运营和商业利益指南
Shallow understanding Net core routing
麒麟信安云平台全新升级!
How to add aplayer music player in blog
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
Pychart ide Download
Lowcode: four ways to help transportation companies enhance supply chain management
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
Nerf: the ultimate replacement for deepfake?
随机推荐
Skimage learning (1)
Establishment of solid development environment
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
管理VDI的几个最佳实践
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
LeetCode 1043. Separate the array to get the maximum and daily questions
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
How to implement safety practice in software development stage
LeetCode 1477. 找两个和为目标值且不重叠的子数组 每日一题
LeetCode 120. 三角形最小路径和 每日一题
LeetCode 1031. Maximum sum of two non overlapping subarrays
无法链接远程redis服务器(解决办法百分百)
LeetCode 648(C#)
浅谈 Apache Doris FE 处理查询 SQL 源码解析
LeetCode 1981. Minimize the difference between the target value and the selected element one question per day
LeetCode 213. Home raiding II daily question
Leetcode brush questions day49
Proxmox VE重装后,如何无损挂载原有的数据盘?