-
Notifications
You must be signed in to change notification settings - Fork 0
/
J.exs
62 lines (58 loc) · 1.73 KB
/
J.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
defmodule Main do
def readInt do
"" |> IO.gets |> String.trim |> String.split |> Enum.map(&String.to_integer/1)
end
def recognize(str) do
str = String.to_charlist(str)
resp = Enum.reverse('Resposta')
perg = Enum.reverse('Pergunta')
num = Enum.reverse('Numero')
{_, ret} = Enum.reduce(str, {[], -1}, fn(ch, {acc, ret}) ->
cond do
ret != -1 ->
{[], ret}
([ch] ++ acc) == perg ->
{[], 0}
([ch] ++ acc) == resp ->
{[], 1}
([ch] ++ acc) == num ->
{[], 2}
true ->
{[ch] ++ acc, ret} end end)
ret
end
def go(map) do
str = IO.gets("") |> String.trim
x = recognize(str)
if x == 1 do
[head | [res]] = String.split(str, ":")
[_ | [num]] = String.split(head)
on = String.trim(num) |> String.to_integer
go(Map.put(map, on, res))
else
[_, a | _] = String.split(str, [" ", "!"])
map[String.to_integer(a)]
end
end
def task do
str = IO.gets("") |> String.trim
if str != "Ole Ole Ola" do
[head | [perg]] = str |> String.trim |> String.split(":")
[_ | [num]] = String.split(head)
on = String.trim(num) |> String.to_integer
perg = String.trim(perg)
#IO.puts perg
ans = go(%{})
#IO.puts (perg <> ans)
Map.put(task(), on, perg <> ans)
else
%{}
end
end
def main do
list = Map.to_list(task())
for {_, value} <- list, do: IO.puts value
end
end
IO.gets("")
Main.main()