当前位置:网站首页>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
边栏推荐
- SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
- Rpcms method of obtaining articles under the specified classification
- mysql官网下载:Linux的mysql8.x版本(图文详解)
- How to implement safety practice in software development stage
- LeetCode 403. 青蛙过河 每日一题
- LeetCode 1186. Delete once to get the sub array maximum and daily question
- Mrs offline data analysis: process OBS data through Flink job
- Matplotlib绘制三维图形
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- [Huang ah code] Why do I suggest you choose go instead of PHP?
猜你喜欢
随机推荐
LeetCode 403. Frog crossing the river daily
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
LeetCode 312. Poke balloon daily
LeetCode 300. 最长递增子序列 每日一题
蓝桥杯 决赛 异或变换 100分
Test case management tool recommendation
Skimage learning (3) -- adapt the gray filter to RGB images, separate colors by immunohistochemical staining, and filter the maximum value of the region
Proxmox VE重装后,如何无损挂载原有的数据盘?
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
LeetCode 1155. N ways to roll dice one question per day
LeetCode 213. Home raiding II daily question
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
A tour of grpc:03 - proto serialization / deserialization
DNS 系列(一):为什么更新了 DNS 记录不生效?
How to add aplayer music player in blog
自定义View必备知识,Android研发岗必问30+道高级面试题
LeetCode 1049. 最后一块石头的重量 II 每日一题
MySQL implements the query of merging two fields into one field









