Prath
But get confused
fgntfg
Show me your code than, and we will figure out what wrong with the code
Prath
Okay
Snusmumriken
Input:
1
5
Sam 40.08
Riya 30.7
Harry 41
Anne 35.2
Peter 36.6
Output:
Harry
Explanation:
The maximum score of student is 41 which belong to "Harry"
Solution using FFI : )
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)
Prath
Thx you very much
Prath
Using lua
Prath
How many changes
Prath
Plz
Snusmumriken
I'm bored to rewrite it in pure Lua.
Prath
What's change plz
Snusmumriken
Лол, такой булшит использовать ффи для такой фигни.
Prath
Could you write it in notebook then share plz
Prath
Plz only last plz
Snusmumriken
Could you write it in notebook then share plz
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 coolest = {name = "", score = -math.huge}
for i = 1, count do
local studentname, score
while not studentname do
print("Write " .. i .. " student (name score):")
local line = io.read("*l")
studentname, score = line:match("(%w+).-(%-?%d+%.?%d*)")
if studentname then
score = tonumber(score)
print("Student #" .. i .. ": ", studentname, "score: ", score)
if score > coolest.score then
coolest.name = studentname
coolest.score = score
end
end
end
end
print("Coolest student is ", coolest.name, ", he's score is:", coolest.score)
Prath
Thx you very much
Prath
I was searched but not get
Snusmumriken
Why do you need ffi for it?
Prath
Actually currently learning lua
Snusmumriken
Prath
On codechef coding platform
Prath
Can we solve this by table as input in lua
Prath
But here input in one line how to do
Snusmumriken
Prath
Okay thx
fgntfg
What is next? You will come with next task from codedef?
fgntfg
Хмм, я придумал страшно не эффективный алгоритм поиска максимума.
fgntfg
Придет ещё раз - напишу такой код, что плакать захочется. O(n!) или что-то типа того.
Snusmumriken
Топово
Snusmumriken
Будем закидывать их предельно неэффективными решениями
Snusmumriken
Мой вариант с FFI вон память жрёт без необходимости.
EN3RGY DRAGON
А что такое асинхронность?
Snusmumriken
А что такое асинхронность?
Это когда несколько функций поочерёдно выполняются по кусочкам, потом ставятся на паузу и переходят к следующим. И так пока не будут выполнены.
fgntfg
Ммм, поиск максимума на корутинах
Snusmumriken
Ну, простейший аналог корутины — это какая-нибудь структура типа
local task = {}
function task:isDone()
...
if a an b and c then
return result
end
end
Ближе к конечным автоматам, но тоже работает и может поражать асинхронностью. Правда, сам код в isDone приходится писать не прямо, а через задницу, как для конечного автомата.
Anton
Snusmumriken
Anton
Мап-редьюснутый.
Snusmumriken
string.lower and string.upper.
Snusmumriken
Read the doc pls. Lua has tutorial books and list of functions:
https://www.lua.org/manual/5.1/
Read it.
Snusmumriken
This chat is not your "task solver". You MUST solve it by yourself.
Highly Likely
Есть тут кто-нибудь, кто успешно РУКАМИ (без мингв) собрал и поставил на винду Lua 5.1 + Luarocks под 5.1?
Highly Likely
У меня уже это выглядит как какой-то невыполнимый квест и накатить Линукс второй осью звучит уже значительно более простой задачей
Highly Likely
Потому что он полумертвый как минимум
Highly Likely
Но это скорее просто хотелка
Highly Likely
Емнип это не оригинал, но надо посмотреть
Highly Likely
Но суть от этого конечно сильно не меняется
Highly Likely
Не может же быть такого, что эту связку на винде руками поставить невозможно
Highly Likely
Я знал, что Винда не про разработку, но не подозревал, что настолько
Highly Likely
Я вот просто размышляю, насколько мне это принципиально уже
Highly Likely
накатить среду разработки на винде
Highly Likely
Highly Likely
Я каким-то образом на рабочей машине смог их настроить и подружить
Highly Likely
А вот на своем компе уже второй день е... мучаюсь
Highly Likely
Короче, пойду я дальше писать код на этих ваших Юникса
Highly Likely
А Винду оставлю для поиграть
Highly Likely
Безумие какое-то
Snusmumriken
Leon174
С busted такая же фигня была. И тоже куча страдальцев с проблемами под виндой. Нашел pure вариант на замену, тесты переписал, и послал к чертовой бабке этот бустед со всеми его геморроидальными шишками.
Highly Likely
Snusmumriken
Луарокс отлично подсоединяется к ВС, покопайся в конфигах
Highly Likely
А вот дальше распихать все по путям и настроить их взаимодействие уже нечто за гранью моего понимания
Алексей
Ребята привет, может тут есть кто то , кто бы мог за определенную плату, довести до ума небольшой скрипт в lua для node mcu?
Snusmumriken
Alexey
Prath
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 coolest = {name = "", score = -math.huge}
for i = 1, count do
local studentname, score
while not studentname do
print("Write " .. i .. " student (name score):")
local line = io.read("*l")
studentname, score = line:match("(%w+).-(%-?%d+%.?%d*)")
if studentname then
score = tonumber(score)
print("Student #" .. i .. ": ", studentname, "score: ", score)
if score > coolest.score then
coolest.name = studentname
coolest.score = score
end
end
end
end
print("Coolest student is ", coolest.name, ", he's score is:", coolest.score)
How to arrange name in ascending order if two students having same score??
Prath
Plz help me
Prath
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 coolest = {name = "", score = -math.huge}
for i = 1, count do
local studentname, score
while not studentname do
print("Write " .. i .. " student (name score):")
local line = io.read("*l")
studentname, score = line:match("(%w+).-(%-?%d+%.?%d*)")
if studentname then
score = tonumber(score)
print("Student #" .. i .. ": ", studentname, "score: ", score)
if score > coolest.score then
coolest.name = studentname
coolest.score = score
end
end
end
end
print("Coolest student is ", coolest.name, ", he's score is:", coolest.score)
How to print name of that two person having same and print there name by alphabet order??
Prath
What changes in code to do??
Snusmumriken
Prath
I will search but not find
Snusmumriken
Prath
Plz one help
Prath
Plz plz
Snusmumriken
No.