-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaiza_shiritori.ruby
More file actions
59 lines (53 loc) · 1.1 KB
/
paiza_shiritori.ruby
File metadata and controls
59 lines (53 loc) · 1.1 KB
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
# しりとりプログラム
# 名鉄でんちゃん
# 2024/1/25
# データ数を入力する
def error_msg()
puts "正の整数を入力してください"
end
def correct(num1,num2)
if num1 == num2 then
puts "Yes"
end
end
puts "正の整数を入力してください"
while true
data1 = gets.chomp
begin
num = data1.to_i
if num < 1 then
puts "1未満の整数が入力されています"
error_msg()
else
break
end
rescue
error_msg()
end
end
a_str = ""
b_str = ""
count = 1
for i in 0...num do
puts "文字を入力してください"
data2 = gets.chomp
N = data2.length
a_str = data2[0]
#puts a_str
if i == 0 then
b_str = data2[N-1]
else
if a_str == b_str then
#puts count
b_str = data2[N-1]
count += 1
else
output_b_str = b_str
output_a_str = a_str
msg = output_b_str + " " + output_a_str
puts msg
break
end
end
end
correct(num,count)