PR
Size: a a a
PR
f
PR
f
PR
PR
PR
PR
f
PR
PR
PR
PR
S
local ffi = require'ffi'
ffi.cdef[[
typedef struct Student {
const char * name;
float score;
} Student;]]
local case, count
while not case do
print("Write testcase count (number):")
case = tonumber(io.read("*l"))
end
while not count do
print("Write students count (number):")
count = tonumber(io.read("*l"))
end
local students = ffi.new("Student[?]", count)
for i = 0, count - 1 do
local studentname, score
while not studentname do
print("Write " .. i + 1 .. " student (name score):")
local line = io.read("*l")
studentname, score = line:match("(%w+).-(%-?%d+%.?%d*)")
if studentname then
print("Student #" .. i .. ": ", studentname, "score: ", score)
students[i].name = studentname
students[i].score = tonumber(score)
end
end
end
local maxstudent = students[0]
for i = 1, count - 1 do
if students[i].score > maxstudent.score then
maxstudent = students[i]
end
end
print("Coolest student is ", ffi.string(maxstudent.name), ", he's score is:", maxstudent.score)
PR
PR