![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
漆黑的莫莫
这个作者很懒,什么都没留下…
展开
-
C语言文件读写细节
而不是在预想的指定位置追加方式打开空文件,可以正常的写入文件。读起写文件时,虽然不会新建文件,但是会将原有数据覆盖,即。都是在文件尾处写数据,添加数据,不删除原有数据。都会新建一个文件,所以文件从头开始读或写。,并非是全覆盖,而是写到哪,覆盖到哪。即使指定文件指针位置,原创 2024-01-13 09:35:45 · 475 阅读 · 0 评论 -
C++ 读写文件
#include <iostream>#include <fstream>#include <string>using namespace std;int main(){ ifstream inFile("1.txt", ios::in); //以文本模式打开in.txt备读 if (!inFile) { //打开失败 perror("error opening source file."); exit(1);原创 2022-04-06 09:33:28 · 533 阅读 · 0 评论 -
C语言 计算程序经过的时间
#include<stdio.h>#include<Windows.h>void test();int main(){ DWORD start, end; start = GetTickCount(); test(); end = GetTickCount(); int time = end - start; printf("经过的时间为: %d 毫秒\n", time); return 0;}void test(){ Sleep(3000);}原创 2021-12-30 10:59:33 · 621 阅读 · 0 评论 -
0-1 背包问题 回溯法
#include<iostream>#include<vector>using namespace std;int goodsSum;int capacityKnapsack;int bestValue = INT_MIN;vector<int>* goodsWeight;vector<int>* goodsValue;vector<bool> bestPut;void backTrack(int depth, int wei原创 2021-11-26 10:45:22 · 558 阅读 · 0 评论 -
分糖果-C语言
题目有n个小朋友围坐成一圈。老师给每个小朋友随机发偶数个糖果,然后进行下面的游戏:每个小朋友都把自己的糖果分一半给左手边的孩子。一轮分糖后,拥有奇数颗糖的孩子由老师补给1个糖果,从而变成偶数。反复进行这个游戏,直到所有小朋友的糖果数都相同为止。你的任务是预测在已知的初始糖果情形下,老师一共需要补发多少个糖果。输入格式:程序首先读入一个整数N(2< N< 100),表示小朋友的人数。接着是一行用空格分开的N个偶数(每个偶数不大于1000,不小于2)输出格式:要求程序输出一个整数原创 2020-05-13 07:19:32 · 1427 阅读 · 0 评论 -
回文数字-C语言
题目观察数字:12321,123321 都有一个共同的特征,无论从左到右读还是从右向左读,都是相同的。这样的数字叫做:回文数字。本题要求你找到一些5位或6位的十进制数字。满足如下要求:该数字的各个数位之和等于输入的整数。输入格式:一个正整数 n (10< n< 100), 表示要求满足的数位和。输出格式:若干行,每行包含一个满足要求的5位或6位整数。数字按从小到大的顺序排列。如果没有满足条件的,输出:-1输入样例:44 输出样例:9989949999458转载 2020-05-14 12:23:00 · 956 阅读 · 0 评论 -
蛇行矩阵-C语言
题目蛇形矩阵是由1开始的自然数依次排列成的一个矩阵上三角形。输入格式:本题有多组数据,每组数据由一个正整数N组成。(N不大于100)输出格式:对于每一组数据,输出一个N行的蛇形矩阵。两组输出之间不要额外的空行。矩阵三角中同一行的数字用一个空格分开。行尾不要多余的空格。输入样例:5输出样例:1 3 6 10 152 5 9 144 8 137 1211参考解答:#include<stdio.h>int main(){ int N,t=1,k1=2原创 2020-05-12 07:42:00 · 200 阅读 · 0 评论 -
希尔排序(步长折半)
#include<stdio.h>void shell_sort(int arr[],int length);int main(){ int arr[20]; int i; for (i = 0; i < 20; i++) { arr[i] = 20 - i; } shell_sort(arr, 20); for (i = 0; i < 20; i++) { printf("%4d ", arr[i]); if ((i + 1) % 10 ==原创 2021-01-05 10:15:13 · 357 阅读 · 0 评论 -
归并排序(递归实现)
#include<stdio.h>int merge(int data[], int low, int mid, int high, int space[]);int merge_sort(int data[], int low, int high, int space[]);int MergeSort(int arr[], int length);int main(){ int arr[20]; for (int i = 0; i < 20; i++) { arr原创 2021-01-02 22:16:40 · 158 阅读 · 0 评论 -
模板_图
#include<iostream>#include<queue>#include<stack>using namespace std;template<class numtype>class Graph; //图类的声明template<class numtype>class AdjVNode //邻接点类的定义{ public: AdjVNode(int num):index_value(num), next(NULL)原创 2020-12-19 14:52:39 · 83 阅读 · 1 评论 -
模板_队列
#include<iostream>using namespace std;template<class numtype>class LinkQueue{ public: LinkQueue(int max_size = 50); ~LinkQueue(); bool EnterQueue(numtype x); //声明 入队 函数 bool DeleteQueue(numtype *x); //声明 出队 函数 bool IsEmpty(); //原创 2020-12-19 14:51:51 · 103 阅读 · 1 评论 -
平均查找长度(散列 顺序 二分)
以学生班级 姓名作为信息,进行平均查找长度的演示#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#define STUDENTS_SUM 30 //学生总数#define HASH_TABLE_SIZE 40 //哈希表长度#define MAX_PRIME 37 //小于等于哈希表长度大于元素个数的最大素数typedef struct student原创 2020-12-12 15:52:30 · 1416 阅读 · 0 评论 -
BFS与DFS
邻接矩阵存储图的DFS与BFS#include <stdio.h>#include<stdlib.h>typedef enum {FALSE, TRUE} BOOL;#define MaxVertexNum 10 /* 最大顶点数设为10 */#define INFINITY 65535 /* ∞设为双字节无符号整数的最大值65535*/typedef char Vertex; /* 用顶点下标表示顶点,为字符型 */typedef int Weigh原创 2020-11-29 17:14:03 · 160 阅读 · 0 评论 -
模板_栈
#include<iostream>using namespace std;template<class numtype>class LinkStack{ public: LinkStack(); ~LinkStack(); bool Push(numtype x); //声明 压栈 函数 bool Pop(numtype *x); //声明 弹栈 函数 bool IsEmpty(); //声明 判空 函数 bool IsFull(); //声明原创 2020-11-21 22:17:32 · 82 阅读 · 0 评论 -
建立二叉树(用二叉链表存储),并进行遍历
问题描述:建立一棵用二叉链表方式存储的二叉树,并对其进行遍历(先序、中序和后序),打印输出遍历结果。基本要求:从键盘输入先序序列,以二叉链表作为存储结构,建立二叉树(以先序来建立)并对其进行遍历(先序、中序、后序),然后将遍历结果打印输出。`在这里插入代码片`要求采用递归和非递归两种方法实现。输入样例:ABC**DE*G**F***输出样例:先序:ABCDEGF中序:CBEGDFA后序:CGEFDBA递归实现:#include<stdio.h>#includ原创 2020-11-20 21:14:55 · 37727 阅读 · 22 评论 -
哈夫曼编码与解码
纪念我逝去的三天时间:被 堆溢出 这个Bug困扰了许久,甚至开始怀疑编译器有问题在经历了艰难险阻后 (其实最后发现只是少写个 1终于解决了问题代码如下:#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct HFM_Tree_Node{ double weight; //用来存放各个结点的权值 unsigned int parent, LChild, RChild;原创 2020-11-19 12:33:06 · 732 阅读 · 3 评论 -
循环队列(有标志符)
#include<stdio.h>#include<stdlib.h>#define TRUE 1#define FALSE 0#define QueueElementType int#define MAX_SIZE 50#define LEN sizeof(SeqQueue)typedef struct { QueueElementType element[MAX_SIZE]; int front; int rear; int tag;}SeqQueu原创 2020-10-15 08:57:20 · 357 阅读 · 0 评论 -
用栈来完成表达式求值
#include<stdio.h>#include<stdlib.h>#include<math.h>#define TRUE 1#define FALSE 0#define MAX_SIZE 50#define LEN sizeof(LinkStackNode)#define StackElementType chartypedef struct node{ StackElementType data; struct node* next;}原创 2020-10-15 08:27:06 · 138 阅读 · 0 评论 -
字符单链表按字符类型一化三
纪念一下把我心态差点搞爆炸的C语言问题:指针在函数中的传递题目如下:已知有单链表表示的线性表中含有三类字符的数据元素(如字母字符、数字字符和其他字符),试编写算法来构造三个循环链表表示的线性表,使每个表中只含同一类的字符,且利用原表中的结点空间作为这三个表的结点空间,头结点可另辟空间。#include<stdio.h>#include<stdlib.h>#define LEN sizeof(List)typedef struct list{ char ch; s原创 2020-10-02 10:53:50 · 396 阅读 · 0 评论 -
图书管理系统
C语言课程设计#include<stdio.h>#include<stdlib.h>#include<string.h>int Sum_Readers = 0;int Sum_Books = 50;typedef struct Book{ int num; char name[60]; char author[30]; int all_sum; int now_sum;}book;typedef struct Reader{ int原创 2020-07-03 16:28:36 · 1025 阅读 · 0 评论 -
快速排序法实现双向链表排序
#include<stdio.h>#include<stdlib.h>#define LEN sizeof(List)typedef struct ListNode{ int num; int data; struct ListNode *pri; struct ListNode *next;}List;List *create(){ List *head=NULL,*p,*tail,*pri; int num,data; scanf("%d%d",&原创 2020-06-09 07:59:12 · 1302 阅读 · 1 评论 -
选择排序法实现单链表排序
利用选择排序法来进行排序#include<stdio.h>#include<stdlib.h>#define LEN sizeof(List)typedef struct ListNode{ int num; int data; struct ListNode *next;}List;List *create(){ int num,data; List *p,*tail,*head=NULL; scanf("%d%d",&num,&da原创 2020-06-08 15:42:39 · 776 阅读 · 0 评论 -
模板_树
#include<iostream>using namespace std;template <typename T>struct BSNode{ //初始化 只赋予权值 BSNode(T t):value(t),lchild(NULL),rchild(NULL) {} //BSNode() = default; T value; //节点的值 BSNode<T>* lchild; //左孩子原创 2020-11-21 22:15:17 · 120 阅读 · 1 评论