当然这么做并不适用于范围超级大的时候
range = (1..1000).to_ap range.sample(5)
以上可以取得5个不重复的1-1000内的数字
C++中定义与使用数组跟C语言中是一样的。具体定义与使用方法可以参考如下程序段:
int a[5] // 定义一个含5个元素的int类型的数组double b[5]={3.2, 3.5, 0.8, 8, 5,3} // 定义一个含5个元素的double类型的数组并初始化char c[] ="abcd" // 定义一个字符数组,并初始化a[0] = c[0] // 将字符数组的第一个字符所对应的ASCII码值赋值给数组a的第一个元素printf("%lf", b[3]) // 输出数组b的第4个元素(数组下标从0开始)
c中是strstr.ruby 1.9.3中包含:
include? other_str → true or false click to toggle source
Returns true if str contains the given string or character.
"hello".include? "lo" #=>true
"hello".include? "ol" #=>false
"hello".include? ?h #=>true