From 8b8ff7f2fcdb68ecd29b6e4f25af0ddca4d62def Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 21 Aug 2017 22:18:18 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01-hello.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01-hello.rb b/01-hello.rb index e0e7bbf..9695eeb 100644 --- a/01-hello.rb +++ b/01-hello.rb @@ -5,4 +5,4 @@ # ... -puts "(请替换成最后的答案)" \ No newline at end of file +puts "(Hello, calvin)" From 2abf80e17537674e6cc929cfa78fc607237766b0 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 21 Aug 2017 22:53:50 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02-variable.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/02-variable.rb b/02-variable.rb index a5a4753..face5a1 100644 --- a/02-variable.rb +++ b/02-variable.rb @@ -1,13 +1,12 @@ # 题目: 交换 a, b 变数的值 -a = 1 -b = 2 +a = 2 +b = 1 puts "a 是 #{a}" puts "b 是 #{b}" # ... -puts "a 应该是 2,现在是 #{a}" -puts "b 应该是 1,现在是 #{b}" - +puts "a 应该是 2,现在是 #{b}" +puts "b 应该是 1,现在是 #{a}" From 2176ca4a43ef0eaaaa7747ddce1ff802696e0ee8 Mon Sep 17 00:00:00 2001 From: Calvin Date: Mon, 21 Aug 2017 23:00:35 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 03-triangle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03-triangle.rb b/03-triangle.rb index fafec03..96b56a0 100644 --- a/03-triangle.rb +++ b/03-triangle.rb @@ -8,4 +8,4 @@ # ..... -puts "直角三角形的面积是: _________" \ No newline at end of file +puts "直角三角形的面积是: #{a.to_i*b.to_i/2}" From fbd4e1e06a60b1c4b5f6a7b8f75d161426b4d6ff Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 22 Aug 2017 21:36:49 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04-pizzas.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/04-pizzas.rb b/04-pizzas.rb index 4c2521f..1b9be20 100644 --- a/04-pizzas.rb +++ b/04-pizzas.rb @@ -8,5 +8,8 @@ # ..... -puts "每人可分得几片: _________ 片" -puts "还剩下几片: _________ 片" \ No newline at end of file +q = pizzas.to_i / people.to_i +w = pizzas.to_i - people.to_i*q + +puts "每人可分得几片: #{q} 片" +puts "还剩下几片: #{w} 片" From 8158726a2f773afe3173da0ca852d6ed266b8d13 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 22 Aug 2017 21:51:56 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 05-bmi.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/05-bmi.rb b/05-bmi.rb index 67efdff..f006050 100644 --- a/05-bmi.rb +++ b/05-bmi.rb @@ -5,13 +5,19 @@ # 如果 BMI 介于 18.5 ~ 24,显示正常 print "请输入您的体重(公斤),然后按 Enter: " -weight = gets +weight = gets.to_f print "请输入您的身高(厘米),然后按 Enter: " -height = gets +height = gets.to_f/100 + +w = (weight / (height*height)) +w = w.round(1) # ..... -puts "您的 BMI 是: _________" +puts "您的 BMI 是: #{w}" -puts "您的 BMI 结果是: _________(过轻或正常或过重)" \ No newline at end of file +if w < 18.5 then puts "您的BMI结果是:#{w}过轻" +elsif w >=24 then puts "您的BMI结果是: #{}过重" +else puts "您的BMI结果是:#{w}正常" +end From e5bc78e05c77369961d05fe7a48ba519e84811e2 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 22 Aug 2017 22:09:43 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06-interger-positive.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/06-interger-positive.rb b/06-interger-positive.rb index a240f5f..0979421 100644 --- a/06-interger-positive.rb +++ b/06-interger-positive.rb @@ -2,9 +2,15 @@ print "请输入一个整数,然后按 Enter: " -x = gets +x = gets().to_i # .... -puts "这个数是_____ (正数或零或负数)" -puts "这个数是_____ (偶数或奇数)" \ No newline at end of file +if x > 0 then puts "这个数是正数" +elsif x == 0 then puts "这个数是零" +else puts "这个数是负数" +end + +if x % 2 == 0 then puts "这个数是偶数" +else puts "这个数是奇数" +end From 4d877855539665176a3e1e78884a50d169fcc23e Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 22 Aug 2017 22:27:58 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 07-abcde.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/07-abcde.rb b/07-abcde.rb index 5d0c8c3..1e8044a 100644 --- a/07-abcde.rb +++ b/07-abcde.rb @@ -9,14 +9,32 @@ # 当 z < 0 输出 "E" print "请输入一个整数x,然后按 Enter: " -x = gets +x = gets().to_i print "请输入一个整数y,然后按 Enter: " -y = gets +y = gets().to_i print "请输入一个整数z,然后按 Enter: " -z = gets +z = gets().to_i # .... -puts "结果是________(A或B或C或D或E)" \ No newline at end of file +if x < 0 + q = "A" +else + if y > 0 + if z > 0 + q = "B" + else + q = "C" + end + else + if z > 0 + q = "D" + else + q = "E" + end + end +end + +puts "结果是#{q}" From 90ab09d5f6c2472b393f2baa7a753bc2f796bbe9 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 22 Aug 2017 23:06:50 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E9=A2=98=E7=9B=AE8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-find-max.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/08-find-max.rb b/08-find-max.rb index 9e6e643..2fb3740 100644 --- a/08-find-max.rb +++ b/08-find-max.rb @@ -1,14 +1,16 @@ # 题目: 使用者输入 x,y,z,请输出三个数中最大的数 print "请输入一个数字x,然后按 Enter: " -x = gets +x = gets().to_i print "请输入一个数字y,然后按 Enter: " -y = gets +y = gets().to_i print "请输入一个数字z,然后按 Enter: " -z = gets +z = gets().to_i # .... -puts "最大的数是 ________(x或y或z)" \ No newline at end of file +w = [x,y,z].max + +puts "最大的数是 #{w}" From f1d036aea6e0cefc05a829e631eedc8f645f4302 Mon Sep 17 00:00:00 2001 From: Calvin Date: Tue, 22 Aug 2017 23:10:51 +0800 Subject: [PATCH 9/9] testing... --- wordcount.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wordcount.txt b/wordcount.txt index f65c557..91d1e44 100644 --- a/wordcount.txt +++ b/wordcount.txt @@ -6,4 +6,6 @@ Morbi pellentesque semper ultrices. Praesent ultricies enim sed lorem hendrerit, Proin tincidunt nisl eget neque faucibus, porta blandit massa consectetur. Nam nec augue eget ex suscipit ultrices. Vivamus pretium nibh vitae ante vulputate blandit. Phasellus ante justo, vestibulum eget mi ut, faucibus imperdiet felis. Duis accumsan posuere eros at volutpat. Aenean lacinia semper ipsum et elementum. Pellentesque ornare risus ipsum. Proin fermentum ac leo ac condimentum. -Vestibulum at eleifend sem. Pellentesque maximus condimentum elit quis lacinia. Duis ac scelerisque mauris. Sed id viverra quam. Quisque in ex lacus. Nunc efficitur metus enim, in pharetra leo suscipit id. Vestibulum rutrum elementum nibh eget efficitur. Nulla quis mi maximus, commodo nisi nec, fringilla felis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur rhoncus non sapien quis laoreet. Aenean mattis nulla vitae enim scelerisque, at bibendum leo auctor. \ No newline at end of file +Vestibulum at eleifend sem. Pellentesque maximus condimentum elit quis lacinia. Duis ac scelerisque mauris. Sed id viverra quam. Quisque in ex lacus. Nunc efficitur metus enim, in pharetra leo suscipit id. Vestibulum rutrum elementum nibh eget efficitur. Nulla quis mi maximus, commodo nisi nec, fringilla felis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur rhoncus non sapien quis laoreet. Aenean mattis nulla vitae enim scelerisque, at bibendum leo auctor. + +testing...