- 博客(62)
- 收藏
- 关注
原创 Linux下目录权限以及目录/proc, /sys, /SElinux, /bin, /usr/lib, /usr/local, /var, /tmp作用,安装gcc,gdb,vim
Linux下的文件权限分为r(可读/可浏览)、w(可写/可创建删除)、x(可执行/可进入)。文件操作用户分为:u(文件所有者)、g(文件所属组)、o(其他用户)、a(所有人)。创建一个目录的默认权限为775。执行ls需要r(可读/可浏览)权限,执行mkdir、cd、rm、mv均需要x(可执行/可进入)权限。/proc 文件系统是一种内核和内核模块用来向进程(process) 发送信息的机制...
2019-06-04 13:38:24
804
原创 数据结构单链表
链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。#include <stdio.h>#include <stdlib.h>#include "SList.h"#include <assert.h>#include <malloc.h>PNode SListBuyNode(DateTy...
2019-05-11 14:06:25
216
原创 数据结构顺序表
线性结构是一个有序数据元素的集合,常用的线性结构有:线性表,栈,队列,双队列,数组,串等。顺序表是用一段物理地址连续的存储空间单元依次存储数据元素的线性结构。分为静态顺序表和动态顺序表。顺序表的基本操作:增删查改等操作。#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include &...
2019-05-10 14:39:32
1079
1
原创 时间复杂度和空间复杂度
一个算法的好坏取决于其运行速度与所需要的额外空间,即时间复杂度与空间复杂度。一个算法所花费的时间与其中语句的执行次数成正比例,算法中基本操作的执行次数,为算法的时间复杂度。时间复杂度不用时间来衡量,而是用基本语句的执行次数来衡量,这是因为每个计算法执行语句的速度都是不一样的,一个算法放在不同的计算机上执行会出现不同的时间,从而用基本语句的执行次数来衡量时间复杂度。计算时间复杂度的时候通常不用...
2019-05-06 11:37:22
657
原创 C语言文件操作
围绕文件相关的基本操作:1.打开文件:FILE* fopen(const char* path, const char* mode)其中path为打开文件的地址,mode为打开方式,打开方式为w是写,打开方式为r为读。返回值为一个文件指针。2.关闭文件int fclose(FILE* fp);fp为关闭文件的文件指针。关闭成功返回0,否则返回-1。打开文件而没有关闭会造成资源泄漏!3...
2019-05-05 17:15:42
125
原创 C语言动态内存管理
void* malloc(size_t size)malloc函数用来开辟一段连续的内存空间,开辟成功返回值为这块内存空间的地址,开辟失败返回值为NULL,size为空间的大小,单位为字节。在用malloc开辟空间后要检查是否开辟内存成功,使用完这段内存后要用free(void* ptr)释放内存,否则会造成内存泄漏。void* calloc(size_t num,size_t size)c...
2019-05-05 15:20:31
242
原创 C语言自定义类型
C语言的自定义类型有:结构体、枚举、联合体等。结构体类型的创建通常用以下格式:struct tag { //此处的member是数据类型,可以是int,char,short,long,long long, //float,double,指针类型等,也可以是自定义类型 member list1; //成员1 member list2; //成员2 member list3;...
2019-05-05 12:47:43
752
原创 动态内存通讯录
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <malloc.h>#include <errno.h>//#define MaxPerson 300 typedef struct...
2019-05-05 10:19:53
188
原创 C语言实现memmove
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void* Mymemmove(void* dest, const void* src, size_t num) { if (dest == NULL || src == NULL) { return NULL; } //...
2019-04-19 15:48:28
226
原创 C语言实现memcpy
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void* Mymemcpy(void* dest,const void* src,size_t num) { if (dest == NULL || src == NULL) { return NULL; } //将vo...
2019-04-19 14:59:50
185
原创 C语言实现strcmp
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>int Mystrcmp(char* str1, char* str2) { assert(*str1); assert(*str2); while (*str1 != '\0...
2019-04-19 14:25:49
594
原创 C语言实现strchr
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>char* Mystrchr(char* str, char c) { assert(*str); while (*str != '\0') { if (*str == c)...
2019-04-15 12:07:22
422
原创 C语言实现strstr
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>char* Mystrstr(char* str1, char* str2) { assert(*str1); assert(*str2); char* temp1 = str...
2019-04-15 11:46:01
724
原创 C语言模拟实现strcat
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>char* mystrcat(char* str1,char* str2) { assert(*str1); assert(*str2); char* p = str1; //...
2019-04-11 15:59:12
183
原创 C语言模拟实现strcpy
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <assert.h>char* mystrcpy(char* str1, char* str2) { assert(*str1); assert(*str2); //str1的每一个元素都赋值st...
2019-04-11 15:52:52
269
原创 喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水, 给20元,可以喝多少汽水
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int main() { int money = 20; int bottle = 0; while (money != 0) { bottle += money; money /= 2; } printf("%d\...
2019-04-11 15:49:27
338
原创 一个数组中只有两个数字是出现一次,其他所有数字都出现了两次,找出这两个数字
用数组遍历的方法,遍历两遍,每一遍找到一个单独的数字#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void FindNum(int arr[], int len) { for (int i = 0; i < len; ++i) { int j = 0; for ...
2019-04-11 15:47:32
238
原创 判断一个字符串是否为另外一个字符串旋转之后的字符串
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>void Judge_turn(char* p1, char* p2) { assert(*p1); assert(*p2);...
2019-04-11 15:42:37
197
原创 实现一个函数,可以左旋字符串中的k个字符
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>void Left_turn(char* p, int k) { assert(*p); int len = strlen(p...
2019-04-10 17:55:24
263
原创 杨氏矩阵中查找一个数字是否存在,时间复杂度小于O(N)
有一个二维数组.数组的每行从左到右是递增的,每列从上到下是递增的.在这样的数组中查找一个数字是否存在。时间复杂度小于O(N);数组:1 2 32 3 43 4 51 3 42 4 54 5 61 2 34 5 67 8 9因为杨氏矩阵每行每列都是递增的,所以把要找的数字跟每行的最后一个元素比较,如果比每行的最后一个元素大,就寻找下一行。如果比最后一个元素小,就寻找这行的...
2019-04-10 16:52:22
369
原创 调整数组使奇数全部都位于偶数前面
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void Rank(int arr[], int length) { int left = 0; int right = length - 1; while (left < right) { if (arr[left]...
2019-04-10 16:21:46
215
原创 C语言扫雷
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h> #include <stdlib.h> #include <time.h>#define Max_row 9#define Max_col 9#define Mine_count 10//初始化,1表示雷,x表示未翻开void Init(char ...
2019-04-05 22:05:34
192
原创 有一个字符数组的内容为:"student a am i", 请你将数组的内容改为"i am a student".
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>void Allexchange(char* str) { int len = strlen(str) - 1; if (*str == '\0') { return; }...
2019-04-05 22:02:28
187
原创 一组数据中只有一个数字出现了一次。其他所有数字都是成对出现的。找出这个数
利用异或具有交换律和结合律的性质,用一个ret依次与数组中的元素相异或,两个相同的数字就会异或为0,最后会剩下一个单独的数字,即为要找的数#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int main() { int arr[11] = {0}; printf("输入11个...
2019-04-05 21:17:04
315
原创 用位操作求两个数的平均值
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int average(int a,int b) { int aver = 0; //相当于每一位都分成三类,第一类:1和1的时候相与,相当于求平均值, //第二类:1和0的时候异或再右移一位,相当于求平均值 //第三类...
2019-04-05 19:23:36
315
原创 二进制位模式从左到右翻转
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>unsigned int reverse_bit(unsigned int value) { unsigned int sum = 0; for (int i = 0; i < 32; i++) { //取出每一位跟1相...
2019-04-05 17:48:40
740
原创 C语言输出杨辉三角
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void Pascal_Triangle(int n) { int arr[100][100] = { 0 }; for (int i = 0; i < n; ++i) { for (int j = 0; j <=...
2019-04-05 17:17:17
802
5
原创 通过供词判断凶手
日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个嫌疑犯的一个。以下为4个嫌疑犯的供词。A说:不是我。B说:是C。C说:是D。D说:C在胡说已知3个人说了真话,1个人说的是假话。现在请根据这些信息,写一个程序来确定到底谁是凶手。#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include ...
2019-04-05 16:26:33
206
原创 5位运动员参加了10米台跳水比赛,对他们的预测进行排序
5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果A选手说:B第二,我第三;B选手说:我第二,E第四;C选手说:我第一,D第二;D选手说:C最后,我第三;E选手说:我第四,A第一;比赛结束后,每位选手都说对了一半,请确定比赛的名次把a,b,c,d,e从1遍历到5,因为他们每人都说对了一半,所以每个人所说的两句话的逻辑异或为1。为了不让他们出现相同的名次,如果他们的名次相乘为12...
2019-04-05 15:49:58
412
原创 C语言五子棋,可以电脑对战,也可以玩家对战
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <time.h>#define Max_Row 15 //使用宏定义,以便以后修改棋盘大小#define Max_Col 15 //使用宏定义,以便以后修改棋盘大小char ChessBoard[...
2019-03-29 15:26:44
1419
2
原创 递归输出数字
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void ShowNum(int num) { if (num > 9) { ShowNum(num / 10); } printf("%d ", num%10);}int main() { int num;...
2019-03-28 18:40:42
496
原创 递归求n的k次方
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h> #include <stdlib.h>int Second(int n,int k) { /*int sum = 1; for (int i = 1; i <= k; ++i) { sum *= n; } return sum;*/ if (k ==...
2019-03-28 18:19:55
823
原创 递归和非递归实现strlen
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int str(char* p) { //int length=0; //while (*p != '\0') { // ++length; // ++p; //} //return length; if (*p == ...
2019-03-28 17:50:25
175
原创 递归逆置字符串
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>void reverse_string(char* string) { if (*string == '\0') { return 0; } else { reverse_string(string+1); ...
2019-03-28 17:19:15
491
原创 递归求数字每位之和
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int Digitsum(int n) { if (n/10==0) { return n; } else { return n%10+Digitsum(n/10); }}int main(){ int n, ...
2019-03-28 16:22:04
1208
原创 递归求阶乘
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int Factorial(int n) { if (n == 1) { return 1; } else { return n*Factorial (n - 1); }}int main() { int n, ...
2019-03-28 16:12:42
169
原创 求第n个斐波那契数
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int Successione_di_Fibonacci(int n) {////非递归//int num1 = 1,num2=1;//int sum = 0,temp ;//for (int i = 1; i <= n...
2019-03-28 16:04:56
265
原创 函数判断素数
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>int Judge(int num) { int flag = 0; for (int i = 2; i < num; ++i) { if (num%i == 0) { flag = 1; } } retu...
2019-03-27 21:14:15
1707
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人