Incremental Method
「遞增法」是符合電腦運作特性的方法。電腦執行程式,一次只做一個動作,完成了一件事才做下一件事。當一個問題太大太多時,化整為零、一個一個解決吧!
合抱之木,生於毫末;九層之臺,起於累土;千里之行,始於足下。謹以此句與大家共勉。
範例:加總數字
無論電腦再怎麼強,還是得一個一個累加數字。

- void summation()
- {
- int array[5] = {3, 6, 9, -8, 1};
- int sum = 0;
- for (int i=0; i<5; i++)
- sum += array[i];
- cout << "總和是" << sum;
- }
- int summation(int array[], int n)
- {
- int sum = 0;
- for (int i=0; i<n; i++)
- sum += array[i];
- return sum;
- }
範例:複製字串
無論電腦再怎麼強,還是得逐字複製。

- void copy()
- {
- char s[15] = "incremental";
- char t[15];
- int i;
- for (i=0; s[i] != '\0'; i++)
- t[i] = s[i];
- t[i] = '\0';
- cout << "原本字串" << s;
- cout << "複製之後的字串" << t;
- }
- void copy(char* s, char* t)
- {
- int i;
- for (i=0; s[i]; i++)
- t[i] = s[i];
- t[i] = '\0';
- }
範例:選擇排序法( Selection Sort )
找到第一小的數字,放在第一個位置;再找到第二小的數字,放在第二個位置。一次找一個數字,如此下去就會把所有數字按照順序排好了。

- void selection_sort()
- {
- int array[5] = {3, 6, 9, -8, 1};
- for (int i=0; i<5; i++)
- {
- // 從尚未排序的數字當中,找到第i小的數字。
- int min_index = i;
- for (int j=i+1; j<5; j++)
- if (array[j] < array[min_index])
- min_index = j;
- // 把第i小的數字,放在第i個位置。
- swap(array[i], array[min_index]);
- }
- // 印出排序結果。
- for (int i=0; i<5; i++)
- cout << array[i];
- }
- void selection_sort(int array[], int n)
- {
- for (int i=0; i<n; i++)
- {
- // 從尚未排序的數字當中,找到第i小的數字。
- int min_index = i;
- for (int j=i+1; j<n; j++)
- if (array[j] < array[min_index])
- min_index = j;
- // 把第i小的數字,放在第i個位置。
- swap(array[i], array[min_index]);
- }
- }
範例:印出直角三角形
多字成行,多行成直角三角形。由細微的東西開始,一件一件組起來。

- // 多字成行
- void print_line(int n) // n 是一行的長度
- {
- for (int i=1; i<=n; i++) cout << '@';
- cout << '\n';
- }
- // 多行成直角三角形
- void print_triangle(int n) // n 是行數
- {
- for (int i=n; i>=1; i--) print_line(i);
- }
Incremental Method的更多相关文章
- Oracle E-Business Suite Maintenance Guide Release 12.2(Patching Procedures)
更多内容参考: http://docs.oracle.com/cd/E51111_01/current/acrobat/122ebsmt.zip Preparing for Patching For ...
- (三)ORB特征匹配
ORBSLAM2匹配方法流程 在基于特征点的视觉SLAM系统中,特征匹配是数据关联最重要的方法.特征匹配为后端优化提供初值信息,也为前端提供较好的里程计信息,可见,若特征匹配出现问题,则整个视觉SLA ...
- Android API之android.provider.ContactsContract.RawContacts
android.provider.ContactsContract.RawContacts Constants for the raw contacts table, which contains o ...
- 07-THREE.JS 各种形状的几何图形
<!DOCTYPE html> <html> <head> <title>Example 02.04 - Geometries</title> ...
- Apache Spark 2.2.0 中文文档
Apache Spark 2.2.0 中文文档 - 快速入门 | ApacheCN Geekhoo 关注 2017.09.20 13:55* 字数 2062 阅读 13评论 0喜欢 1 快速入门 使用 ...
- SEMAT[软件工程方法和理论 Software Engineering Method and Theory]
Agile software development Agile software development is a group of software development methods bas ...
- 201904Online Human Action Recognition Based on Incremental Learning of Weighted Covariance Descriptors
论文标题:Online Human Action Recognition Based on Incremental Learning of Weighted Covariance Descriptor ...
- 2.5 – Garbage Collection 自动垃圾回收 Stop-the-world vs. incremental vs. concurrent 垃圾回收策略
2.5 – Garbage Collection 自动垃圾回收 Lua 5.3 Reference Manual http://www.lua.org/manual/5.3/manual.html# ...
- V4 Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 2471245.1)
V4 Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 2471245. ...
随机推荐
- web.xml配置文件详细解读
对于一个J2EE应用的开发者,或者叫java web后台的开发者来说.经常会和web.xml打交道,偶尔用到几个标签不知道啥意思.然后就度娘一下,久而久之虽然大概知道web.xml的基本使用方法,但是 ...
- C# 获取文件夹下的所有文件夹及其文件
//获得当前文件夹下所有文件夹 string path = "D://文件夹"; string[] dirstr = Directory.GetDirectories(path); ...
- QString 编码转换
参考网址:http://blog.csdn.net/lfw19891101/article/details/6641785 (网页保存于:百度云CodeSkill33 --> 全部文件 > ...
- Codeforces 912E - Prime Gift
912E - Prime Gift 思路: 折半枚举+二分check 将素数分成两个集合(最好按奇偶位置来,保证两集合个数相近),这样每个集合枚举出来的小于1e18的积个数小于1e6. 然后二分答案, ...
- Codeforces 534B - Covered Path
534B - Covered Path 思路:贪心,每一秒取尽可能大并且可以达到的速度. 画张图吧,不解释了: 代码: #include<bits/stdc++.h> using name ...
- LeetCode--202--快乐数
问题描述: 编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变 ...
- 20170523xlVBA多条件分类求和一例
Public Sub NextSeven_CodeFrame() Application.ScreenUpdating = False Application.DisplayAlerts = Fals ...
- oracle使用(1)
纯粹是记录工作中使用的分析函数或是语法点,不做其他用处. (1) with as 先举个例子吧: 有两张表,分别为A.B,求得一个字段的值先在表A中寻找,如果A表中存在数据,则输出A表的值:如果A表中 ...
- 42 前端HTML
HTML 1. 概念 HTML 超文本标记语言(Hypertext Markup Language, HTML)是一种用于创建网页的标记语言 . 2.标签 Meta标签 <me ...
- django-celery定时任务以及异步任务and服务器部署并且运行全部过程
Celery 应用Celery之前,我想大家都已经了解了,什么是Celery,Celery可以做什么,等等一些关于Celery的问题,在这里我就不一一解释了. 应用之前,要确保环境中添加了Celery ...