1. 头文件#include2. 数组习惯用法vector iVec(10);//定义10个整数iVec[0] = 10;//第一个元素赋值为10vector iVec(10, -1);// 定义10个整数,每个整数被初始化为-1int ia[ 6 ] = { -2, -1, 0, 1, 2, 10... Read More
posted @ 2015-04-14 18:03 yiyi_xuechen Views(137) Comments(0) Diggs(0) Edit
问题描述Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the tw... Read More
posted @ 2015-04-14 16:41 yiyi_xuechen Views(117) Comments(0) Diggs(0) Edit
一、require函数 用require函数可以把程序分割成多个文件并创建函数库。例如,在myfile.pl中有定义好的Perl函数,可用语句require ("myfile.pl"); 在程序中包含进来。当Perl解释器看到这一语句,就在内置数组变量@INC指定的目录中寻找文件myfile.pl... Read More
posted @ 2015-04-13 19:28 yiyi_xuechen Views(410) Comments(0) Diggs(0) Edit
一、模块简介 模块(module)就是Perl包(package)。Perl的对象基于对包中数据项的引用。 在用其它语言进行面向对象编程时,先声明一个类然后创建该类的对象(实例),特定类所有对象的行为方式是相同的,由类方法确定,可以通过定义新类或从现存类继承来创建类。类是一个Perl包,其中包含... Read More
posted @ 2015-04-13 16:16 yiyi_xuechen Views(246) Comments(0) Diggs(0) Edit
一、引用简介 引用就是指针,可以指向变量、数组、哈希表甚至是子程序。二、使用引用 如果$pointer的值为一个数组的指针,则通过形式@$pointer来访问数组中的元素。形式@$pointer的意义为“取出$pointer中的地址值当作数组使用”。类似的,%$pointer为指向哈希表中第一个... Read More
posted @ 2015-04-13 14:09 yiyi_xuechen Views(582) Comments(0) Diggs(0) Edit
一、文件输入/输出函数 1.基本I/O函数open 允许程序访问文件close 终止文件访问print 文件写入字符串write 向文件写入格式化信息printf 格式化字符串并输出到文件 2. 跳过和重读数据 函数名seek调用语法seek (filevar, distance, relat... Read More
posted @ 2015-04-13 13:46 yiyi_xuechen Views(162) Comments(0) Diggs(0) Edit
一、定义打印格式,formatformat formatnem =二、显示打印格式 1. 将系统变量$~设成所要使用的格式 2. 调用函数write三、在打印格式中显示值 1. 通用的打印格式 2. 格式和局部变量 3. 选择值域格式 4. 输出值域字符四、 输出到其他文件 缺省地,函... Read More
posted @ 2015-04-13 13:40 yiyi_xuechen Views(245) Comments(0) Diggs(0) Edit
一、数组变量的限制 前面讲到的数组变量中,可以通过下标访问其中的元素,但是它们有显著的缺陷,即很难记住那个元素存住什么内容。二、定义 关联数组,哈希表,可以通过任意简单变量值来访问其元素。 为了区分关联数组与普通数组,Perl使用%作为其首字符,而数组变量以@大头。 与其他变量名一样,%后第... Read More
posted @ 2015-04-13 13:26 yiyi_xuechen Views(882) Comments(0) Diggs(0) Edit
一、定义 子程序即执行一个特殊任务的一段分离的代码,它可以使减少重复代码且使程序易读。PERL中,子程序可以出现在程序的任何地方。二、调用 1. 用&调用, &subname; ... sub subname{ ... } 2. 先定义,后调用,可以省略&符号... Read More
posted @ 2015-04-13 13:08 yiyi_xuechen Views(419) Comments(0) Diggs(0) Edit
一、条件判断if - elsif - else二、循环whileutilforforeachdo - whiledo - utilgoto,last, next, redo三、单行条件语法为statement keyword condexpr。其中keyword可为if、unless、while或u... Read More
posted @ 2015-04-13 01:16 yiyi_xuechen Views(102) Comments(0) Diggs(0) Edit