步长型循环(For语句)
for 语句用来描述已知重复次数的循环结构。
for 语句有两种形式:
(1) for 循环变量:=初值 to 终值 do 语句;
(2) for 循环变量:=初值 downto 终值 do 语句;
例:计算1+2+3+……+99+100的和
program jia; var
i,n,sum:integer;
begin
sum:=...
分类:
其他好文 时间:
2015-07-20 16:47:52
阅读次数:
185
Given an integer array of size n, find all elements that appear more than ? n/3 ? times. The algorithm should run in linear time and in O(1) space.Hint:How many majority elements could it possibly hav...
分类:
其他好文 时间:
2015-07-20 16:28:47
阅读次数:
133
子界类型
如果我们定义一个变量i为integer类型,那么i的值在微型机系统的pascal中,使用2字节的定义表示法,取值范围为-32768~32767。而事实上,每个程序中所用的变量的值都有一个确定的范围。
例如,人的年龄一般不超过150,一个班级的学生不超过100人,一年中的月数不超过12,一月中的天数不超过31,等等。
如果我们能在程序中对所用的变量的值域作具体规定的话,就便于检查出那...
分类:
其他好文 时间:
2015-07-20 13:08:19
阅读次数:
179
Question1Power of TwoGiven an integer, write a function to determine if it is a power of two.This question is pretty simple. If a number is a power of...
分类:
其他好文 时间:
2015-07-20 12:47:54
阅读次数:
99
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 1 class Solution { 2 public: 3 int roma...
分类:
其他好文 时间:
2015-07-20 10:41:04
阅读次数:
98
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer...
分类:
移动开发 时间:
2015-07-20 10:37:56
阅读次数:
130
Given an integer, write a function to determine if it is a power of two. 1 bool isPowerOfTwo(int n) 2 { 3 if(n1)10 {11 if(n%2==0)12 ...
分类:
其他好文 时间:
2015-07-20 10:37:32
阅读次数:
124
Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great...
分类:
其他好文 时间:
2015-07-20 10:33:13
阅读次数:
108
Write a function that takes an unsigned integer and returns the number of ’1' bits it hasFor example, the 32-bit integer ’11' has binary representatio...
分类:
其他好文 时间:
2015-07-20 10:29:37
阅读次数:
104
【012-Integer to Roman(数字转罗马字符)】输入一个数字,将它转成一个罗马数字,输入的数字在[1, 3999]之间。
罗马数字的表示:
个位数举例: (I, 1) (II, 2) (III, 3) (IV, 4) (V, 5) (VI, 6) (VII, 7) (VIII, 8) (IX, 9)
十位数举例:(X, 10) (XI, 11) (XII, 12) (X...
分类:
编程语言 时间:
2015-07-20 09:21:27
阅读次数:
135