pascal

Pascal's Triangle,Pascal's Triangle II

喜夏-厌秋 提交于 2020-01-11 02:29:54
一.Pascal's Triangle Given numRows , generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] class Solution { public: vector<vector<int>> generate(int numRows) { vector<vector<int>> res; if(numRows==0){ return res; } vector<int> row; int size = 0; while(numRows--){ int x = 1;for(int i=1;i<size;i++){ int y = row[i]; row[i]= x+y; x = y; } row.push_back(1); res.push_back(row); size++; } return res; } }; 二.Pascal's Triangle II Given an index k , return the k th row of the Pascal's triangle. For example, given k = 3,

PASCAL语言子集的词法、语法分析器之实现

試著忘記壹切 提交于 2020-01-10 09:27:35
针对简单的文法(PASCAL语言子集),制作相应的词法分析器和递归下降的语法分析器。 文法要求如下: 1、 关键字、标识符、数字等: 1.begin 2.if 3.then 4.while 5.do 6.end 10. 标识符 11. 数字 13.+ 14.- 15.* 16./ 17.: 18.:= 20.< 21.<> 22.<= 23.> 24.>= 25.= 26.; 27.( 28.) 2、 文法规则 : 程序 → begin 语句串 end 语句串 → 语句 { ; 语句 } 语句 → 赋值语句 | 条件语句 | 循环语句 赋值语句 → 变量 := 表达式 条件语句 → if 条件 then ( 语句 | 程序 ) 循环语句 → while 条件 do ( 语句 | 程序 ) 表达式 → 项 { + 项 | - 项 } 条件 → 表达式 关系符 表达式 关系符 → < | <> | <= | > | >= | = 项 → 因子 { * 因子 | / 因子 } 因子 → 变量 | 数字 | ( 表达式 ) 变量 → 标识符 一、 词法分析器 词法分析器的任务是清除源文件中多余的空格、换行、制表符等,识别文法符号。按顺序输出识别的标识符及其种别编号,供语法分析器调用。 代码如下: #include <stdio.h> #include <string.h> #include

How to generate a certain amount of numbers and spread them randomly across a grid?

荒凉一梦 提交于 2020-01-07 09:43:40
问题 I want to generate the number 2 5 times and the number 1 10 times. I'm trying to spread these across a String Grid in Delphi randomly. I also want to fill the rest of the grid that isn't 1 or 2 , with 0 's. I have no idea how to even start here. It would look something like this (P stands for player and there would only be 5 2's and 10 1's): https://gyazo.com/aeef05c3a92ce7847c0f42ad40faa733 回答1: Given a grid with dimensions m × n , create an array of length m * n . Put five 2's and 10 1's in

Exponentiation of real numbers

纵饮孤独 提交于 2020-01-07 05:43:22
问题 I've come across an interesting exercise and it says: Implement a function x^y using standard functions of Turbo Pascal For integer variables I can use for loop but I cannot understand how to work with real variables in this case. I've been thinking about how to do this using Taylor series (can't understand how to use it for exponentiation) and I also found out that x^y = exp(y*log(x)) but there is only ln (natural logarithm) in standard functions... PS I'm not asking you to write code: give

Synchronize () DLL freezes without errors and crashes

自作多情 提交于 2020-01-06 20:09:01
问题 I built a modular program consisting of several programs (exe), and in some cases these modules are also in DLL. There are about 6 modules. All of these modules used functions of a Thread. This thread does not use visual components, what it does is basically analyze huge files (> 1GB). To improve the efficiency and organization, extract all the code relating to this file analysis, which is used by each of the modules. This facilitates updating and find error. The threads worked normally

Statement expected but Function found error in my function code

三世轮回 提交于 2020-01-06 04:43:06
问题 So below is the module of code I have created to verify a user input is between a range but this error keeps appearing below it ' statement expected but function found', any ideas anyone? Many thanks function get_choice(var Options: integer): integer; var choice: integer; begin while (true) do begin write('choose option 1 to', Options); try readln(choice); if (choice>=1) and (choice <=Options) then get_choice := choice else write('invalid range'); except write('not a number'); end; end; 回答1:

System command executes but is immediately backgrounded

末鹿安然 提交于 2020-01-06 03:32:05
问题 I'm attempting to use the TProcess unit to execute ssh to connect to one of my servers and provide me with the shell. It's a rewrite of one I had in Ruby as the execution time for Ruby is very slow. When I run my Process.Execute function, I am presented with the shell but it is immediately backgrounded. Running pgrep ssh reveals that it is running but I have no access to it whatsoever, using fg does not bring it back. The code is as follows for this segment: if HasOption('c', 'connect') then

Pascal splitting line into real and strings

ⅰ亾dé卋堺 提交于 2020-01-05 05:43:07
问题 I know that this language have died a couple of years ago, but still required in most of schools in our country -.- I got file with data, which looks like: Number of lines Name Surname (real type digit) (another real type digit) For e.g. 2 Brat Sunbather 5.66 55.4 Bart Simpson 55.7 45.4 And I need to create result file, which looks like this: Name Surname (Previously given real type digits multiplied) Total For e.g. Brat Sunbather 313.56 Bart Simpson 2528.78 Total: 2842.34 I'm stuck in trying

Atitit.词法分析的理论原理 part2

不想你离开。 提交于 2020-01-05 01:15:32
Atitit. 词法分析的理论原理 part2 1 . 转换图 1 1 .1. 转换图是由程序流程图改进而成的。同样,转换图也可以等价地转换为程序流程图 3 1 .2. 2.2.3 构造词法分析器(2)流程 程序2-1虽然只有26行,却是词法分析器的核心 4 1 .3. 单词存储形式就是三元组(单词 ID ,单词备注,单词行号)。 4 1 .4. 单词流是如何传递给语法分析器的。 5 1 .5. 词法定义 5 1 .6. 词法分析器主要包括:构造转换图与转换表、设计词法分析器算法。 6 1 .7. 超前搜索几个字符与词法定义有关,有些设计不精良的语言可能需要超前搜索三个甚至四个字符才能正确识别单词 7 1. 转换图 从图2-2中,不难发现,其中只有"搜索指针后移一个字符"一种处理动作(方框)。那么,读者不妨想象一下,词法分析器是否就只有这种处理动作呢?仔细分析手工识别单词的过程后,就可以发现事实确实如此。既然词法分析器的流程中条件判断(菱形框)比较复杂,而处理动作非常单一,因此,可以将普通流程图改造成一种专门用于描述条件判断的流程图。具体改造步骤如下: 1)把图2-2中所有上、下菱形(判断)之间的箭头用圆表示。 2)把图2-2中所有的菱形直接用箭头线表示,箭头上写上原菱形的判断成立与否的条件,即可得到图2-3。 图2-3 识别Pascal标识符的状态转换图 这里省略了出错处理

PASCAL语言子集的词法、语法分析器之实现

对着背影说爱祢 提交于 2020-01-04 23:59:09
针对简单的文法(PASCAL语言子集),制作相应的词法分析器和递归下降的语法分析器。 文法要求如下: 1、 关键字、标识符、数字等: 1.begin 2.if 3.then 4.while 5.do 6.end 10.标识符 11.数字 13.+ 14.- 15.* 16./ 17.: 18.:= 20.< 21.<> 22.<= 23.> 24.>= 25.= 26.; 27.( 28.) 2、 文法规则: 程序 → begin 语句串 end 语句串 → 语句 { ; 语句 } 语句 → 赋值语句 | 条件语句 | 循环语句 赋值语句 → 变量 := 表达式 条件语句 → if 条件 then ( 语句 | 程序 ) 循环语句 → while 条件 do ( 语句 | 程序 ) 表达式 → 项 { + 项 | - 项 } 条件 → 表达式 关系符 表达式 关系符 → < | <> | <= | > | >= | = 项 → 因子 { * 因子 | / 因子 } 因子 → 变量 | 数字 | ( 表达式 ) 变量 → 标识符 一、 词法分析器 词法分析器的任务是清除源文件中多余的空格、换行、制表符等,识别文法符号。按顺序输出识别的标识符及其种别编号,供语法分析器调用。 代码如下: #include<stdio.h> #include<string.h> #include