摘要: 已知正整数n,你要利用malloc函数动态开辟一个长度为n的整型数组,然后读取n个整数存入该数组中。再将这n个整数全部改为其相反数(例如10的相反数是-10,-10的相反数是10)的10倍,然后将其输出。最后你要利用free函数将该动态数组所占用的空间释放。 提示:malloc与free的使用,以下 阅读全文
posted @ 2020-12-04 20:54 Auterman 阅读(650) 评论(0) 推荐(0) 编辑
摘要: #设计函数 char *locatesubstr(char *str1,char *str2),查找str2指向的字符串在str1指向的字符串中首次出现的位置,返回指向该位置的指针。若str2指向的字符串不包含在str1指向的字符串中,则返回空指针NULL。 注意这里必须使用指针而不是数组下标来访问 阅读全文
posted @ 2020-12-04 17:16 Auterman 阅读(361) 评论(0) 推荐(0) 编辑
摘要: void delcharfun(char *str,char ch){ int i=0,j=0; while (*(str+i)){ if(*(str+i)==ch){ j=i; while(*(str+j)){ *(str+j)=*(str+j+1); j++; } } else i++; } } 阅读全文
posted @ 2020-12-04 16:48 Auterman 阅读(150) 评论(0) 推荐(0) 编辑
摘要: #unique()函数存在于#include中 ##用法: unique(首地址,末地址) ###该函数会返回一个迭代器,该迭代器为第一个重复元素的地址, 该返回值减去数组名地址即为该函数中不重复元素数量 ##注意:该函数只是将重复的部分移到数组的后面 从而达到数组前面部分元素不重复 ##题目样例: 阅读全文
posted @ 2020-08-22 17:58 Auterman 阅读(168) 评论(0) 推荐(0) 编辑
摘要: #快速排序模板 #include #include using namespace std; int x[100000]; void qsort(int l, int r) { int i = l; int j = r; int mid = x[(l + r) / 2]; do { while (x 阅读全文
posted @ 2020-08-22 17:21 Auterman 阅读(102) 评论(0) 推荐(0) 编辑
摘要: #在STL库中(algorithm)存在nth_elememt()函数能对数组进行处理, 使得所求的第n小的数能够出现在a[n-1]中; ##用法:求函数中第n小的数, nth_element(数组名,数组名+n-1,数组名+数组元素总数); ##注意: 1.nth_element()是将整个数组进 阅读全文
posted @ 2020-08-22 15:16 Auterman 阅读(184) 评论(0) 推荐(0) 编辑
摘要: eg: #include #include #include<string.h> int x[10000]; //记录加工步骤 int order[30][30]; //记录每个物品的工序顺序 int cost[30][30]; //记录每个物品响应工序花费的时间 int work[30][1000 阅读全文
posted @ 2020-08-21 17:10 Auterman 阅读(238) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>库中存在sprintf()函数能将不同类型的数据组合成字符数组 ##sprintf(destination,type,各种数据名) //destination为最终组合成的字符数组返回目标,type为组合的各类型数据的类型(与printf()中使用的相似) inst 阅读全文
posted @ 2020-08-19 17:37 Auterman 阅读(318) 评论(0) 推荐(0) 编辑
摘要: #在#include<stdio.h>中存在sscanf函数能将字符串中分成多个部分,分别转化为不同类型进行返回; ##sscanf(char *s,type,destination) //s为字符数组名,type为转化的种类(与scanf中的格式相同),destination为返回的目标 inst 阅读全文
posted @ 2020-08-19 16:29 Auterman 阅读(288) 评论(0) 推荐(0) 编辑
摘要: int isPrime(int n){ if(n==0||n==1) return 0; else{ for(int i=2;i<=sqrt(n);i++) \\无需特判n==2情况,because 当i==2时,sqrt(n)<2,循环不进行; { if(n%i==0) return 0; } } 阅读全文
posted @ 2020-08-19 11:19 Auterman 阅读(84) 评论(0) 推荐(0) 编辑