#方法
defhelloworld
puts"HelloWorld!"
end
helloworld
#带参数的方法
defhello(name)
puts"Hello#{name}"
end
hello("World!")
hello("Ruby")
#带可变长参数的方法
defhello(*name)
name.each{|x|puts"Hello#{x}"}#each迭代器将name的值传递给x
end
hello("zhao","wang","l..
分类:
其他好文 时间:
2016-05-18 22:13:06
阅读次数:
233
=begin
条件判断语句包括if语句,unless语句,case语句,
=end
#if语句
=begin
if条件then
处理1
elsif条件2then
处理2
else
处理3
end
=end
a=10
b=20
ifa>b
puts"abiggerthanb"
elsifa<b
puts"asmallerthanb"
else
puts"aisequaltob"
end
puts"abiggerthanb"ifa>b
..
分类:
其他好文 时间:
2016-05-18 22:12:44
阅读次数:
203
#迭代器
5.times{puts"HelloWoeld!"}#连续输出4次HelloWorld!
1.upto(10){|i|puts"Thecountis#{i}"}#从1数到10
10.downto(1){|i|puts"Thecountis#{i}"}#从10到1
1.step(10,2){|i|puts"Thecountis#{i}"}#从1到10,步长为2
#each,使用each方法将集合内的对象逐个取出
name=["..
分类:
其他好文 时间:
2016-05-18 22:12:28
阅读次数:
189
=begin
循环,times,while,each,for,until,loop
=end
#times方法
=begin
循环次数.timesdo
循环的处理
end
循环的次数.times{
循环的处理
}
=end
5.timesdo
puts"hello"
end
5.times{|i|
puts"for#{i}‘sloop"
}
#for语句
=begin
for变量in对象do
循环的处理
end
=end
sum=0
..
分类:
其他好文 时间:
2016-05-18 22:11:59
阅读次数:
325
上面的flip-flop的用法,你可以理解成 将 大于等于5和小于等于10的数字打印出来,也就是理解成 puts x if x >=5 && x <=10 ,但是注意你不能写成下面这样 如果写成绿色背景的代码,就会造成输出 大于等于5 小于等于20的数字 问题2 flip-flop的用法 在普通的判 ...
分类:
其他好文 时间:
2016-05-18 12:29:18
阅读次数:
183
getchar() putchar(ch) scanf() 头文件stdio.h getch() getche() 头文件conio.h gets() puts() 头文件stdio.h getch()和getche()函数 都是从键盘上读入一个字符,但getch()函数不将读入的字符回显在显示屏幕 ...
分类:
其他好文 时间:
2016-05-15 12:28:09
阅读次数:
228
Description
Calculate the number of toys that land in each bin of a partitioned toy box.
Mom and dad have a problem - their child John never puts his toys away when he is finished playing with t...
分类:
其他好文 时间:
2016-05-13 03:07:08
阅读次数:
166
在 /board/freescale/t104xrdb/ddr.c文件的initdram函数中
phys_size_t initdram(int board_type)
{
phys_size_tdram_size;
#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_RAMBOOT_PBL)
puts("Initial...
分类:
其他好文 时间:
2016-05-13 02:36:40
阅读次数:
383
思路:构造,显然是一个蝴蝶形状的图
#include
using namespace std;
int main()
{
int n,k,a,b,c,d;
vectorg;
scanf("%d%d",&n,&k);
scanf("%d%d%d%d",&a,&b,&c,&d);
if(n==4)
{
puts("-1");
return 0;
}
if (k<=n...
分类:
其他好文 时间:
2016-05-12 14:38:18
阅读次数:
182