pseudo-code-2012.docx 2013/5/9

Similar documents
0 0 = 1 0 = 0 1 = = 1 1 = 0 0 = 1

邏輯設計 Hw#6 請於 6/13( 五 ) 下課前繳交

Numbers and Fundamental Arithmetic

Chapter 6. Series-Parallel Circuits ISU EE. C.Y. Lee

Algorithms and Complexity

5.5 Using Entropy to Calculate the Natural Direction of a Process in an Isolated System

= lim(x + 1) lim x 1 x 1 (x 2 + 1) 2 (for the latter let y = x2 + 1) lim

GSAS 安裝使用簡介 楊仲準中原大學物理系. Department of Physics, Chung Yuan Christian University

Answers: ( HKMO Heat Events) Created by: Mr. Francis Hung Last updated: 23 November see the remark

EXPERMENT 9. To determination of Quinine by fluorescence spectroscopy. Introduction

生物統計教育訓練 - 課程. Introduction to equivalence, superior, inferior studies in RCT 謝宗成副教授慈濟大學醫學科學研究所. TEL: ext 2015

相關分析. Scatter Diagram. Ch 13 線性迴歸與相關分析. Correlation Analysis. Correlation Analysis. Linear Regression And Correlation Analysis

tan θ(t) = 5 [3 points] And, we are given that d [1 points] Therefore, the velocity of the plane is dx [4 points] (km/min.) [2 points] (The other way)

Chapter 22 Lecture. Essential University Physics Richard Wolfson 2 nd Edition. Electric Potential 電位 Pearson Education, Inc.

1 dx (5%) andˆ x dx converges. x2 +1 a

Chapter 20 Cell Division Summary

14-A Orthogonal and Dual Orthogonal Y = A X

國立中正大學八十一學年度應用數學研究所 碩士班研究生招生考試試題

原子模型 Atomic Model 有了正確的原子模型, 才會發明了雷射

Glossary. Mathematics Glossary. Elementary School Level. English Traditional Chinese

Digital Integrated Circuits Lecture 5: Logical Effort

Statistical Intervals and the Applications. Hsiuying Wang Institute of Statistics National Chiao Tung University Hsinchu, Taiwan

2001 HG2, 2006 HI6, 2010 HI1

Finite Interval( 有限區間 ) open interval ( a, closed interval [ ab, ] = { xa x b} half open( or half closed) interval. Infinite Interval( 無限區間 )

Chapter 1 Linear Regression with One Predictor Variable

Advanced Engineering Mathematics 長榮大學科工系 105 級

Ch2 Linear Transformations and Matrices

Candidates Performance in Paper I (Q1-4, )

雷射原理. The Principle of Laser. 授課教授 : 林彥勝博士 Contents

基因演算法 學習速成 南台科技大學電機系趙春棠講解

台灣大學開放式課程 有機化學乙 蔡蘊明教授 本著作除另有註明, 作者皆為蔡蘊明教授, 所有內容皆採用創用 CC 姓名標示 - 非商業使用 - 相同方式分享 3.0 台灣授權條款釋出

命名, 構象分析及合成簡介 (Nomenclature, Conformational Analysis, and an Introduction to Synthesis)

Multiple sequence alignment (MSA)

Page 1

Chapter 1 Physics and Measurement

Linear Regression. Applied Linear Regression Models (Kutner, Nachtsheim, Neter, Li) hsuhl (NUK) SDA Regression 1 / 34

Work Energy And Power 功, 能量及功率

統計學 Spring 2011 授課教師 : 統計系余清祥日期 :2011 年 3 月 22 日第十三章 : 變異數分析與實驗設計

Digital Image Processing

Differential Equations (DE)

課程名稱 : 電路學 (2) 授課教師 : 楊武智 期 :96 學年度第 2 學期

Lecture Notes on Propensity Score Matching

SIMPLE Algorithm for Two-Dimensional Flow - Fluid Flow and Heat Transfer

在雲層閃光放電之前就開始提前釋放出離子是非常重要的因素 所有 FOREND 放電式避雷針都有離子加速裝置支援離子產生器 在產品設計時, 為增加電場更大範圍, 使用電極支援大氣離子化,

KWUN TONG GOVERNMENT SECONDARY SCHOOL 觀塘官立中學 (Office) Shun Lee Estate Kwun Tong, Kowloon 上學期測驗

Candidates Performance in Paper I (Q1-4, )

授課大綱 課號課程名稱選別開課系級學分 結果預視

REAXYS NEW REAXYS. RAEXYS 教育訓練 PPT HOW YOU THINK HOW YOU WORK

大原利明 算法点竄指南 点竄術 算 額 絵馬堂

2019 年第 51 屆國際化學奧林匹亞競賽 國內初選筆試 - 選擇題答案卷

期中考前回顧 助教 : 王珊彗. Copyright 2009 Cengage Learning

PHI7470 Topics in Applied Philosophy: The Philosopher and Sociology

Factorizing a Polynomial. What is Quadratic Equation? What is Polynomial Factorization? Factorizing by grouping like terms. Factorizing by identities

d) There is a Web page that includes links to both Web page A and Web page B.

4 內流場之熱對流 (Internal Flow Heat Convection)

Ch.9 Liquids and Solids

2. Suppose that a consumer has the utility function

Chapter 1 Linear Regression with One Predictor Variable

GRE 精确 完整 数学预测机经 发布适用 2015 年 10 月考试

2( 2 r 2 2r) rdrdθ. 4. Your result fits the correct answer: get 2 pts, if you make a slight mistake, get 1 pt. 0 r 1

Elementary Number Theory An Algebraic Apporach

Chapter 13 Thin-layer chromatography. Shin-Hun Juang, Ph.D.

Statistics and Econometrics I

Chapter 5-7 Errors, Random Errors, and Statistical Data in Chemical Analyses

壓差式迴路式均熱片之研製 Fabrication of Pressure-Difference Loop Heat Spreader

HKDSE Chemistry Paper 2 Q.1 & Q.3

CHAPTER 4. Thermochemistry ( 熱化學是熱力學的一支, 在化學反應或相變化過程中發生的能量吸收或釋出, 若以吸放熱的形式表現, 即為熱化學研究的對象 ) Chap. 4 Thermochemistry

The dynamic N1-methyladenosine methylome in eukaryotic messenger RNA 报告人 : 沈胤

Multimedia Communications Fall 07 Midterm Exam (Close Book)

Chapter 2 the z-transform. 2.1 definition 2.2 properties of ROC 2.3 the inverse z-transform 2.4 z-transform properties

Beckman Coulter Cytomics FC500 Flow Cytometry 自動化五色螢光流式細胞分析儀 Training Course

A Direct Simulation Method for Continuous Variable Transmission with Component-wise Design Specifications

FUNDAMENTALS OF FLUID MECHANICS. Chapter 8 Pipe Flow. Jyh-Cherng. Shieh Department of Bio-Industrial

Frequency Response (Bode Plot) with MATLAB

MECHANICS OF MATERIALS

數位系統設計 Digital System Design

MRDFG 的周期界的計算的提升計畫編號 :NSC E 執行期限 : 94 年 8 月 1 日至 94 年 7 月 31 日主持人 : 趙玉政治大學資管系計畫參與人員 :

第 3 章有機化學反應種類及酸鹼有機反應. 一 ) 有機化反應的種類及有機反應機制 (organic reactions and their mechanism)

Ch 13 Acids and Bases

Chapter 5-6 Experimental Error

USTC SNST 2014 Autumn Semester Lecture Series

Revised Dynamic Optimal Training of Three-Layer Neural Network

Boundary Influence On The Entropy Of A Lozi-Type Map. Cellular Neural Networks : Defect Patterns And Stability

On the Quark model based on virtual spacetime and the origin of fractional charge

FUNDAMENTALS OF FLUID MECHANICS Chapter 3 Fluids in Motion - The Bernoulli Equation

CHAPTER 2. Energy Bands and Carrier Concentration in Thermal Equilibrium

在破裂多孔介質中的情形 底下是我們考慮的抛物線微分方程式. is a domain and = f. in f. . Denote absolute permeability by. P in. k in. p in. and. and. , and external source by

Chapter 8 Lecture. Essential University Physics Richard Wolfson 2 nd Edition. Gravity 重力 Pearson Education, Inc. Slide 8-1

個體經濟學二. Ch10. Price taking firm. * Price taking firm: revenue = P(x) x = P x. profit = total revenur total cost

論文與專利寫作暨學術 倫理期末報告 班級 : 碩化一甲學號 :MA 姓名 : 林郡澤老師 : 黃常寧

Ch2. Atoms, Molecules and Ions

Chapter 1 Introduction: Matter and Measurement

( 选出不同类别的单词 ) ( 照样子完成填空 ) e.g. one three

Default risk premium + Liquidity premium + maturity risk premium (2) PV of perpetuity

行政院國家科學委員會補助專題研究計畫 成果報告 期中進度報告 ( 計畫名稱 )

Chapter 7 Propositional and Predicate Logic

世界自然基金會米埔濕地中學教育項目 紅樹林生態 學生工作紙 ( 參考答案 ) WWF Mai Po Wetland Secondary School Education Programme Mangrove Ecology Student Worksheet (Reference Answer)

Permutation Tests for Difference between Two Multivariate Allometric Patterns

Lecture Note on Linear Algebra 14. Linear Independence, Bases and Coordinates

Chapter 1 Thermodynamics and Phase Diagrams

Transcription:

Pseudo-code 偽代碼 & Flow charts 流程圖 : Sum Bubble sort 1 Prime factors of Magic square Total & Average Bubble sort 2 Factors of Zodiac (simple) Quadratic equation Train fare 1+2+...+n <= limit Calculator Digital Clock Animal of the year Square numbers Word Count 三角形測試 Decimal to Binary Largest numbers Skip Comments HKCEE 198x MTR fare Smallest & largest Greetings Middle number Leap year test Trim spaces GCD/LCM Odd and Even Linear search Euclidean Algorithm Encoding / Decoding Binary search Admission Fee ASCII table a,b,c? 8 5 3 a,b,c? 7 3 10 a,b,c? 5 8 8 a,b,c? 4 0 2 a,b,c? 3 1 3 開始 輸入 a,b,c a,b,c? 5 9 1 a,b,c? 4 6 3 a,b,c? 5 5 0 a,b,c? 7 2 9 a,b,c? 1 3 2 a>b? x=b c b=b+5 x>a? b>c? c=b 3 b=c 3 x=c b a=b c b>c? b>5? x=b 2 x=c 2 x=c 4 x=x+3 結束 a,b,c,x 的最終值是什麼? p.1

Sum sum = 0 as long as sum < 10 do input x sum = sum + x end do output sum inputs: 1 2 3 4 5 output: inputs: 2 3 4 5 output: Total & Average Total = 0, Avg = 0, n = 0 IPUT x WHILE x > 0 DO Total = Total + x n = n+1 IPUT x ED WHILE IF n>0 THE Avg = Total / n OUTPUT Avg inputs: 1 2 3 4 0 output: inputs: 0 1 2 3 4 output: inputs: 1 2 3-4 0 output: Quadratic equation IPUT A,B,C D=B 2-4AC IF D=0 THE X = -B/2A OUTPUT X ED IF D<0 THE OUTPUT O REAL ROOT ED IF D>0 THE B D x1 2A B D x2 2A OUTPUT x1,x2 ED sum = 0 只要 sum<10 進行輸入 x sum = sum + x 輸出 sum Total = 0, Avg = 0, n = 0 輸入 x 只要 x > 0 進行 Total = Total + x n = n+1 輸入 x 如果 n>0 則 Avg = Total / n 輸出 Avg 輸入 A,B,C D=B 2-4AC 若果 D=0 則 X = -B/2A 輸出 X 若果 D<0 則 輸出 " 沒有根 " 若果 D>0 則 B D x1 2A B D x2 2A 輸出 x1,x2 p.2

Digital Clock IPUT HH,MM,SS WHILE HH<24 DO OUTPUT HH,MM,SS SS = SS+1 輸入 HH,MM,SS 只要 HH<24 進行輸出 HH,MM,SS SS = SS+1 IF SS=60 THE MM = MM+1 SS = 0 EDIF IF MM=60 THE HH = HH+1 MM = 0 EDIF IF HH=24 THE HH = 0 ED WHILE 若果 SS=60 則 MM = MM+1 及 SS = 0 若果 MM=60 則 HH = HH+1 及 MM = 0 若果 HH=24 則 HH = 0 試把下列 算法 (Algorithm) 改寫為 C 程式 ( 三角形測試 ) 步驟 : (1) 要求使用者輸入三角形各邊長, 並分別儲存在變量 A, B 及 C 內 ; 假設 A B C (i) (2) 儲存 C 2 的數值在變量 S1 內 C (3) 儲存 A 2 + B 2 的數值在變量 S2 內 A B (4) 跟據下表, 輸出不同的結果 條件 輸出 i 若 C 大於或等於 A 及 B 之和 not a (triangle) ( 不是三角形 ) (ii) A B C 否則 ii 若 C 2 iii 若 C 2 iv 若 C 2 小於 A 2 及 B 2 之和 an acute ( 銳角三角形 ) 等於 A 2 及 B 2 之和 a right-angled ( 直角三角形 ) 大於 A 2 及 B 2 之和 an obtuse ( 鈍角三角形 ) (iii) A B C (iv) A C B p.3

HKCEE 1991 count = 1 score = 0 R = 7 WHILE count 5 IPUT x IF(abs(R-x)<3) THE score = score + 2 ELSE score = score - 1 count = count+1 ED WHILE OUTPUT score 輸入數值 input values: 2, 5, 8, 0, 10 count = 1 score = 0 R = 7 只要 count 5 便進行輸入 x 如果 (abs(r-x)<3) 則 score = score + 2 否則 score = score - 1 count = count+1 輸出 score Greetings Time Message 00:00 Mid-night 午夜 00:01-11:59 Morning 早晨 12:00 oon 正午 12:01-17:59 Afternoon 下午 18:00-23:59 Evening 晚上 sum = 1+2+3+...+n <= limit IPUT limit sum = 0 n = 1 WHILE sum+n <= limit DO OUTPUT n sum = sum+n n = n+1 ED WHILE OUTPUT sum Trim spaces: inputs: abcd pqrxyz outputs: abcd pqrxyz 輸入 limit sum = 0 n = 1 只要 sum+n <= limit 便進行輸出 n sum = sum+n n = n+1 輸出 sum previous current previous char current char (c) space non-space space --- output c non-space output c output c inword p.4

Decimal to Binary: simple version: reversed binary IPUT dec WHILE dec>0 DO r = dec % 2 dec = dec / 2 OUTPUT r ED WHILE final version s = ULL IPUT dec WHILE dec>0 DO r = dec % 2 dec = dec / 2 attach r to the front of s ED WHILE OUTPUT s MTR Fare IPUT age, fr_stn, to_stn fare = (to_stn-fr_stn)*2 IF fare<5 THE fare = 5 IF age<12 THE fare = fare / 2 IF age>60 THE fare = fare / 2 OUTPUT fare age = 999 只要 age>0 便進行輸入 age, fr_stn, to_stn fare = (to_stn-fr_stn)*2 如果 fare<5 則 fare = 5 如果 age<12 則 fare = fare / 2 如果 age>60 則 fare = fare / 2 輸出 fare Find the middle number: IPUT 輸入 X,,Z IF 如果 X> THE 則 IF X>Z THE IF >Z THE OUTPUT ELSE OUTPUT Z ELSE 否則 OUTPUT X ED IF ELSE IF >Z THE IF X>Z THE OUTPUT X ELSE OUTPUT Z ELSE OUTPUT B: x % y remainder of x/y ED IF ED IF 輸入 x,y,z 如果 x>y 則如果 x>z 則如果 y>z 則輸出 y 否則輸出 z 否則輸出 x 否則如果 y>z 則如果 x>z 則輸出 x 否則輸出 z 否則輸出 y p.5

GCD/HCF (Simple & Straight forward) IPUT two positive integers (A & B) IF A<B THE swap A & B GCD=0 n=b WHILE n>1 AD GCD<1 DO IF A & B are both divisible by n THE GCD=n ELSE n=n-1 ED DO OUTPUT GCD 輸入兩整數 (A & B) 如果 A<B 則對換 A & B GCD=0 n=b 只要 n>1 及 GCD<1 便進行如果 A & B 可被 n 整除則 GCD=n 否則 n=n-1 輸出 GCD LCM (Simple & Straight forward) IPUT two positive integers (A & B) IF A<B THE swap A & B LCM=0 輸入兩整數 (A & B) 如果 A<B 則對換 A & B LCM=0 n=a // n=max(a,b) n=a WHILE n<axb AD LCM<1 DO IF n is divisible by both A & B THE LCM=n ELSE n=n+1 ED DO OUTPUT LCM 只要 n<axb 及 LCM<1 便進行如果 n 可被 A & B 整除則 LCM=n 否則 n=n+1 輸出 LCM LCM(A,B) GCD(A,B) = A B Euclidean Algorithm: Repeat Find C = A%B (remainder of A divided by B) Until C=0 B will be the HCF(A,B) A B C=A%B 1 20 12 8 20%12=8 2 12 8 4 12%8=4 3 8 4 0 8%4=0 HCF = 4 p.6

GCD Euclidean Algorithm 歐基里德算法/ 輾轉相除法 計算 A 和 B 的最大公因數 (GCD/HCF) 要求使用者輸入兩個整數 (A 和 B) 若 A 的值少於 B 的值, 則換轉 (Swap) A 和 B 的值 只要 B 的值大於 0 便進行把 A 除 B 的餘數 賦予 C 把 B 的值賦予 A 把 C 的值賦予 B 把 A 的值賦予 HCF 輸出 HCF 假設 Admission Fee ($100) 輸入 dow, time, age fee = 100 如果 (dow=0 或 dow=6) 則 fee = fee * 1.1 否則如果 (time<14) 則 fee = fee * 0.9 Prime factors 質因數 of n: IPUT n d=2 WHILE n>1 DO IF n is divisible by d THE OUTPUT d n = n/d ELSE d = d+1 ED IF ED WHILE Factors of n 因數 : IPUT n d=2 WHILE d<=n DO IF n is divisible by d THE OUTPUT d d = d+1 ED WHILE (i) "Swap" 是一個預定處理程序 (ii) X % 的結果是 X 除 的餘數 如果 (age>60) 則 fee = fee * 0.5 否則如果 (age<12 或學生 ) 如果 (dow=0 或 dow=6) 則 fee = fee * 0.8 否則 fee = fee * 0.5 輸出 fee 輸入 n d=2 只要 n>1 進行如果 n 可被 d 整除則輸出 d n = n/d 否則 d = d+1 輸入 n d=2 只要 d<=n 進行如果 n 可被 d 整除則輸出 d d = d+1 p.7

Encode / Decode (ASCII code of 'A'=65) 編碼 / 解碼 65 70 75 80 85 90 A B C D E F G H I J K L M O P Q R S T U V W X Z Q R S T U V W X Z A B C D E F G H I J K L M O P Encode 編碼 A(65) Q(81) B(66) R(82) I(73) (89) J(74) Z(90) K(75) A(65) L(76) B(66) (89) O(79) Z(90) P(80) Encode 編碼 IPUT alphabet c 輸入字母 c n = 16 + ASCII code of c n = 字母 c 的 ASCII 碼 IF n>90 THE n=n-26 如果 n<75 c = the n'th char in ASCII table 則 n=n+16 OUTPUT alphabet c 否則 n=n-10 c = ASCII 編碼表內第 n 個字符 輸出字母 c Decode 解碼輸入字母 c n = 字母 c 的 ASCII 碼 - 16 如果 n<65 則 n=n+10 c = ASCII 編碼表內第 n 個字符輸出字母 c Linear Search, Binary Search, Bubble Sort: Train Fare: Word Count: Skip Comments: Ping-Pong Rebound: x++,y++ (0,20) (80,0) To determine if year (yy) is a Leap ear or not: yy = 999 只要 yy>0 便進行輸入 yy 如果 yy%400=0 則 Leapear="" 否則如果 yy%4=0 則如果 yy%100 0 則 Leapear="" 否則 Leapear="" 否則 Leapear="" 輸出 Leapear p.8