当前位置: 首页 > news >正文

个人网站建设思路深圳有哪些做网站公司

个人网站建设思路,深圳有哪些做网站公司,洛可可,福州网站seo推广优化文章目录 前言一、数组的概念二、一维数组的定义三、一维数组的初始化四、一维数组的使用及举例1. 元素顺次前移的问题2. 数组元素逆序调整问题3. 统计输入的各个数据的个数 五、课后练习1. 从数组中查找某个元素2. 求一个数组中元素的平均值和均方差3. 编程统计某班某次考试的… 文章目录 前言一、数组的概念二、一维数组的定义三、一维数组的初始化四、一维数组的使用及举例1. 元素顺次前移的问题2. 数组元素逆序调整问题3. 统计输入的各个数据的个数 五、课后练习1. 从数组中查找某个元素2. 求一个数组中元素的平均值和均方差3. 编程统计某班某次考试的平均成绩和均方差4. 求一个列表的中位数5. 使用数组输出Fibonacci数列的前40项6. 二分查找——在一个有序列表中查找某个元素7. 改进的二分查找——在一个有序列表中查找某个元素 总结 前言 C是一种面向对象编程语言,其中数组是其中一种重要的数据结构。数组是一个数据对象集合,其中每个元素都具有相同的数据类型,并且可以根据其所在的位置(即索引)进行查询和引用。 一、数组的概念 二、一维数组的定义 三、一维数组的初始化 四、一维数组的使用及举例 1. 元素顺次前移的问题 有一个整数数组数组元素由n个用键盘输入试着将数组的第一个元素移到数组末尾其余的数组元素依次前移一个位置后顺序输出。 2. 数组元素逆序调整问题 将一个数组中的元素逆序后输出。 3. 统计输入的各个数据的个数 有[0, 20]范围的整数N个统计每个数的个数和不同整数的个数。 五、课后练习 1. 从数组中查找某个元素 从数组中查找某个元素如果找到返回该元素在数组中的索引位置数组下标否则提示“无此元素”。 2. 求一个数组中元素的平均值和均方差 均方差一般指标准差。 标准差Standard Deviation 数学术语是方差样本中各数据与样本平均数的差的平方和的平均数叫做样本方差的算术平方根用σ表示。标准差能反映一个数据集的离散程度。平均数相同的两组数据标准差未必相同。 σ Σ i 1 n ( x i − μ ) 2 n \sigma \sqrt{\frac{\Sigma^{n}_{i1}(x_i - \mu)^2}{n}} σnΣi1n​(xi​−μ)2​ ​ 简单来说标准差是一组数据和平均值分散程度的一种度量。一个较大的标准差代表大部分数值和其平均值之间差异较大一个较小的标准差代表这些数值较接近平均值。 #includeiostream #includeiomanip #includecmath using namespace std; int main() {const int size 100;//如果想加大数组可以改变它double a[size];int index 0;double sum 0;double average, s0, mu;cout请输入数据输入任意字母确定结束输入endl;while(cina[index]) {if(index size-1) break;}cout输入数据为endl;for(int i0; iindex-1; i)cout setw(8) a[i];coutendl;for(int i0; iindex-1; i)sum a[i];average sum/(index-1); //求平均值cout Average: average endl;for(int i0; iindex-1; i)s (a[i]-average)*(a[i]-average);mu sqrt(s/(index-1)); //求均方差cout均方差为 mu endl;return 0; }3. 编程统计某班某次考试的平均成绩和均方差 本题同上一题。 4. 求一个列表的中位数 对任意给定的长度为n的已排好序的整型数组求该数组元素的中位数。 中位数Median又称中值统计学中的专有名词是按大小顺序排列的一组数据中居于中间位置的数。如果被考察的这组数据的个数为偶数个通常取最中间的两个数值的平均数作为中位数。 【算法分析】先对列表排序如果列表的个数是奇数则中间 那个数就是这组数据的中位数如果列表的个数是偶数则中间 那两个数的算术平均值就是这组数据的中位数。 #include iostream //#include cstdlib #include algorithmusing namespace std;//求一个列表的中位数 int main() {//int arr[] {66, 93, 36, 48, 96, 83, 45, 60, 90, 53};int arr[] {136, 140, 129, 180, 124, 154, 146, 145, 158, 175, 165, 148};int len sizeof(arr) / sizeof(arr[0]);coutlength: lenendl;for(int i0; ilen; i)coutarr[i] ;coutendl;sort(arr, arrlen); //第一个参数是要排序的数组的起始地址, 第二个参数是结束的地址最后一个数据的后一个数据的地址for(int i0; ilen; i)coutarr[i] ;int m len/2;float median;if(len % 2 0) {median (arr[m-1] arr[m])/2.0;} else {median arr[m];}cout\nThe median number is: medianendl; } 5. 使用数组输出Fibonacci数列的前40项 #include iostream #include iomanip using namespace std; //输出斐波那契数列前40项 int main() {int n40;int f[n];//构造斐波那契数列 f[0] 1;f[1] 1;for(int i2; in; i){f[i] f[i-1] f[i-2];}//输出斐波那契数列 for(int i0; in; i) {cout setw(12) f[i];if ((i1) % 5 0) { //每行输出10项cout endl;}}return 0; }运行程序输出如下。 1 1 2 3 58 13 21 34 5589 144 233 377 610987 1597 2584 4181 676510946 17711 28657 46368 75025121393 196418 317811 514229 8320401346269 2178309 3524578 5702887 922746514930352 24157817 39088169 63245986 1023341556. 二分查找——在一个有序列表中查找某个元素 代码如下示例 #include iostream using namespace std;// Classic binary search algorithm // value: the value being searched int binarySearch(int arr[], int size, int value) { int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value) //value in the left part of the arrayright mid - 1;else if (arr[mid] value) //value in the right part of the arrayleft mid 1;else if (arr[mid] value)return mid;}return -1; // the element is not exist in the array }int main(void) {int arr[] {2, 3, 4, 10, 10, 10, 10, 10, 40};int n sizeof(arr) / sizeof(arr[0]);int x 10;int result binarySearch(arr, n, x);if (result -1) {printf(Element is not present in the array\n);} else {printf(Element is present at index %d\n, result);}return 0; } 运行程序输出如下。 Element is present at index 4其实被查找元素10在列表中的第一次出现的索引位置为3第二次出现的索引位置才是4。因为被查找列表元素是有序的如果被查找元素在列表中如果有重复出现的话那么这些相同的元素肯定是相邻的这就出现了查找某个元素在列表中第一次出现或者最后一次出现的位置的情况。所以二分查找可以进一步进行有针对性的调整。具体参见下面的代码。 #include iostream using namespace std;// Classic binary search algorithm // value: the value being searched int binarySearch(int arr[], int size, int value) { int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value) //value in the left part of the arrayright mid - 1;else if (arr[mid] value) //value in the right part of the arrayleft mid 1;else if (arr[mid] value)return mid;}return -1; // the element is not exist in the array }//寻找arr中值为value的左侧边界也就是arr中有重复的值寻找第一个等于value的位置 //Find the left boundary of value in arr, which means there are //duplicate values in arr, and find the first position equal to the search value int binarySearchLeft(int arr[], int size, int value) { int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value) //value in the left part of the arrayright mid - 1;else if (arr[mid] value) //value in the right part of the arrayleft mid 1;else if (arr[mid] value) {if (mid 0 || arr[mid - 1] ! value)return mid;elseright mid - 1; //right boundary contracts to the left (right往左侧收缩)}}return -1; // the element is not exist in the array }//寻找arr中值为value的右侧边界也就是arr中有重复的值寻找最后一个等于value的位置 //Find the right boundary of value in arr, which means there are //duplicate values in arr, and find the last position equal to the search value int binarySearchRight(int arr[], int size, int value) {int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value)right mid - 1;else if (arr[mid] value)left mid 1;else if (arr[mid] value) {if (mid size - 1 || arr[mid 1] ! value)return mid;elseleft mid 1; //left boundary contracts to the right (left往右侧收缩)}}return -1; }int main(void) {int arr[] {2, 3, 4, 10, 10, 10, 10, 10, 40};int n sizeof(arr) / sizeof(arr[0]);int x 10;cout binarySearchLeft(arr, n, x) endl; cout binarySearchRight(arr, n, x) endl;return 0; } 运行程序输出如下 3 77. 改进的二分查找——在一个有序列表中查找某个元素 使用二分查找法查找一个列表中的元素是否存在于另一个列表中。 输入 包括3行。 第一行2个数n和q第一个数n为被查找的列表的长度第二个数q为查找元素的个数 第二行是被查找的列表元素 第三行是要查找的列表元素。 输出 q行。每一行为被查找元素在被查找的列表中的位置。 #include iostream using namespace std;// Classic binary search algorithm // value: the value being searched int binarySearch(int arr[], int size, int value) { int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value) //value in the left part of the arrayright mid - 1;else if (arr[mid] value) //value in the right part of the arrayleft mid 1;else if (arr[mid] value)return mid;}return -1; // the element is not exist in the array }//寻找arr中值为value的左侧边界也就是arr中有重复的值寻找第一个等于value的位置 //Find the left boundary of value in arr, which means there are //duplicate values in arr, and find the first position equal to the search value int binarySearchLeft(int arr[], int size, int value) { int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value) //value in the left part of the arrayright mid - 1;else if (arr[mid] value) //value in the right part of the arrayleft mid 1;else if (arr[mid] value) {if (mid 0 || arr[mid - 1] ! value)return mid;elseright mid - 1; //right boundary contracts to the left (right往左侧收缩)}}return -1; // the element is not exist in the array }//寻找arr中值为value的右侧边界也就是arr中有重复的值寻找最后一个等于value的位置 //Find the right boundary of value in arr, which means there are //duplicate values in arr, and find the last position equal to the search value int binarySearchRight(int arr[], int size, int value) {int left 0, right size - 1;while (left right) {int mid left (right - left) / 2;if (arr[mid] value)right mid - 1;else if (arr[mid] value)left mid 1;else if (arr[mid] value) {if (mid size - 1 || arr[mid 1] ! value)return mid;elseleft mid 1; //left boundary contracts to the right (left往右侧收缩)}}return -1; }int main(void) {int n, q;cin n q;int arr[n]; //The array being searchedint arr2[q]; //Elements to search forfor(int i0; in; i) cin arr[i];for(int i0; iq; i) cin arr2[i];int count sizeof(arr) / sizeof(arr[0]);for(int i0; iq; i) {cout binarySearchLeft(arr, count, arr2[i]) binarySearchRight(arr, count, arr2[i]) endl;}return 0; } 程序运行的一次输入输出如下。 7 5 1 2 3 4 5 6 7 2 7 4 3 9 1 1 6 6 3 3 2 2 -1 -1总结 C数组中的数据在内存中是连续存放的每个元素占据相同大小的空间就像排好队一样理解这点非常重要。
http://www.pierceye.com/news/614911/

相关文章:

  • 做网站优化有什么途径什么类型的公司需要做建设网站的
  • 计算机毕设代做网站深圳自适应网站开发
  • 万网主机建设网站流程idc 网站备案
  • 收费用的网站怎么做珠海网站关键词推广
  • 学技巧网站制作网站建设税率多少
  • 高端网站设计平台网页设计模板的网站
  • 万网云服务器网站上线网站开发开票税率
  • 西安高端网站制作公司网站开发需要哪些知识
  • 不错的网站建设公网站建设产品展示型的
  • 泰安住房和城乡建设局网站东莞网站推广哪家好信息
  • 个人网站制作的选题意义简短干净三字公司起名
  • 网站卡密代理怎么做网站建设有关表格
  • 易语言可以做网站么永久免费linux云主机
  • 什么网站可以免费做视频软件网站广告推广价格
  • 网站建设手机软件黄页88收费吗
  • 郑州网站建设多少钱wordpress分享获得积分
  • 贵阳网站设计模板建设工程监理招标网站
  • 上海专业的网页设计公司百度推广优化怎么做的
  • 河南城乡建设厅网站wordpress 主题 字体
  • 网站编辑的工作内容深圳网站设计公司有哪些
  • 设计深圳网站制作网站建设及维护招聘
  • 网站开发实训新的体会wordpress防止机器人注册
  • 购买的网站如何换背景自建网站如何被百度收录
  • 国外外贸网站手机销售网站制作
  • 海外永久网站众车网是哪家公司网站
  • 上海 网站开发 兼职布吉建设网站
  • 做网站资金来源是什么wordpress模版sns
  • 聊城wap网站建设如何分析网站竞争对手
  • 卓业网站建设flash 网站 收费
  • 两学一做 答题 网站自己做网站买东西