算法
文章平均质量分 63
bo_1997_2017
既然选择了,就坚定的学下去。
展开
-
C++ 矩阵乘法
只有当矩阵A的列数与矩阵B的行数相等时A×B才有意义。一个m×n的矩阵a(m,n)左乘一个n×p的矩阵b(n,p),会得到一个m×p的矩阵c(m,p)。1.一个两行三列的矩阵和一个三行两列的矩阵乘法#include#define M 2 //定义A矩阵的行#define N 3 //定义A矩阵的列 B矩阵的行#define P 2 //定义B矩阵原创 2017-09-18 15:52:38 · 1183 阅读 · 0 评论 -
数据结构 P35 算法实现 循环链表的创建与查找
#includeusing namespace std;struct node //创建节点{int date;node *next;};int main(){node *head; //创建头结点head=NULL;int x=1,y1=0; //y1为判断链表现有长度的参数n原创 2017-10-08 11:51:41 · 351 阅读 · 0 评论 -
数据结构 P48 算法实现 栈的应用举例-数制转换
#include using namespace std;#define STACK_INIT_SIZE 100 //初始存储容量#define STACKINCERMENT 10 //存储空间增量struct SqStack //顺序栈的定义{int *base; //栈原创 2017-10-20 21:21:56 · 788 阅读 · 0 评论 -
数据结构 P50 算法实现 栈的应用-行编辑程序
#include #includeusing namespace std;#define STACK_INIT_SIZE 100 //初始存储容量#define STACKINCERMENT 10 //存储空间增量struct SqStack //顺序栈的定义{char *base;原创 2017-10-22 09:32:10 · 479 阅读 · 0 评论 -
数据结构 P49 栈的应用举例-括号匹配的检验
#include #includeusing namespace std;#define STACK_INIT_SIZE 100 //初始存储容量#define STACKINCERMENT 10 //存储空间增量struct SqStack //顺序栈的定义{char *base;原创 2017-10-21 21:49:35 · 316 阅读 · 0 评论 -
数据结构 P62-62 算法实现 单链队列的创建及基本操作
#includeusing namespace std;typedef int QElemType; struct QNode //创建节点结构体{QElemType data;QNode *next;};struct linkqueue //创建链队列结构体{QNode *front; //原创 2017-10-24 19:57:10 · 380 阅读 · 0 评论 -
数据结构 P64-65 算法实现 循环队列的创建和基本操作
#includeusing namespace std;typedef int QElemType;#define MAXQSIZE 100struct linkqueue //创建循环队列结构体{QElemType *base; //初始化的动态分配存储空间 int front; //原创 2017-10-24 21:05:19 · 563 阅读 · 0 评论 -
关于哥德巴赫猜想
/*目的:验证每个大于等于6的偶数,都可表示为两个奇素数之和。背景: 1742年,德国数学家哥德巴赫提出:每一个不小于6的偶数都是两个奇素数之和;每一个不小于9的奇数都是三个奇素数之和。我们容易得出: 4=2+2, 6=3+3,8=5+3, 10=7+3,12=7+5,14=11+3,…… 那么,是不是所有的大于2的偶数,都可以表示为两个素数的呢?素数:除1和本身无原创 2017-11-19 16:47:15 · 581 阅读 · 0 评论 -
PAT-1031.查验身份证(15)
#include#includeusing namespace std;int main(){int N,i,j=0,k=0,B[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2},Z,x;char A[11]={'1','0','X','9','8','7','6','5','4','3','2'};string C; ci原创 2017-12-09 16:11:03 · 286 阅读 · 0 评论 -
PAT-1027.在霍格沃茨找零钱(20)
#includeusing namespace std;int main(){int G[2],S[2],K[2],g,s,k,n;char x;cin>>G[0]>>x>>S[0]>>x>>K[0];cin>>G[1]>>x>>S[1]>>x>>K[1];if(G[0]-G[1]n=1;else if(G[0]>G[1])n=-1;原创 2017-12-09 16:22:28 · 259 阅读 · 0 评论 -
PAT-1030.有几个PAT(25)
#includeusing namespace std;int main(){char c;int num=0,p=0,t=0;while(1){c=getchar(); switch(c){case 'P': p++;break;case 'A': t+=p; t=t%1000000007;break;case 'T': num+原创 2017-12-09 16:27:01 · 211 阅读 · 0 评论 -
PAT-2014.有理数四则运算(20)
#includeusing namespace std;void gys(long long &a, long long &b);void Cout(long long k1,long long a1,long long b1,char s,long long k2,long long a2,long long b2,long long k,long long a,long long原创 2017-12-10 13:50:43 · 634 阅读 · 0 评论 -
PAT-1005.德才论(25)
#includeusing namespace std; int N,L,H;struct stu {int B,C,D,Z;};void order(stu s[],int X);int main(){stu s[100001];int i,j,a[5]={0},M=0;stu A1[100001],A2[100001],A3[100001],A4原创 2017-12-10 16:59:57 · 264 阅读 · 0 评论 -
PAT-1025.插入与归并(25)
#include#includeusing namespace std;int N;int inser(int i,int A[],int B[]);int main(){ int A[100],B[100],C[100]; int i,j,k,temp; cin>>N; for(i=0;i {cin>>A[i];C[i]=A[i];}原创 2017-12-10 19:31:10 · 366 阅读 · 0 评论 -
数据结构 P16 算法实现
冒泡排序-先将最大的数放在最后面 ,将整数序列重新排列成自小至大有序的整数序列原创 2017-09-18 20:49:45 · 475 阅读 · 0 评论 -
数据结构 P20 算法实现 —A=AUB和归并排序
for(int j=0;j<ASIZE+n;++j) //B集合的元素依次与A集合的元素比较 { if(B[i]!=A[j]) //若不同则系数m加一 ++m; if(m==ASIZE+n) //若与A集合所有的元素都不相同则将B集合中的该元素添加到A集合原创 2017-09-19 20:31:23 · 803 阅读 · 0 评论 -
蓝桥杯样题-信用卡号验证
#includeusing namespace std;struct node //创建节点{int data; //data存储该节点的数据int num; //num存储该节点的数位node *pior; //指向上一位数};class原创 2017-10-27 20:58:46 · 458 阅读 · 0 评论 -
蓝桥杯样题-水仙花数(未完全解决)
#includeusing namespace std;void huaduo(int N){unsigned long long x,y=1,b,sum,num[100],a=10; //定义大容量的数据类型int n=1; while(n{ n=1; for(b=y;b!=0;++n) b=b/a; y原创 2017-10-26 20:56:25 · 301 阅读 · 0 评论 -
数据结构 P46-47 算法实现 顺序栈的基本操作
#include using namespace std;#define STACK_INIT_SIZE 100 //初始存储容量#define STACKINCERMENT 10 //存储空间增量struct SqStack //顺序栈的定义{int *base; /原创 2017-10-20 09:40:54 · 511 阅读 · 0 评论 -
数据结构 P43 算法实现 两个一元多项式相乘
/*程序*/#includeusing namespace std;struct node{int coefficient; //系数int exponent; //指数 node *next;};class polynomial //多项式{publi原创 2017-10-14 15:48:53 · 3506 阅读 · 0 评论 -
数据结构 P42-43 算法实现 多项式的建立及加法
/*多项式的建立及加法*/#includeusing namespace std;struct node{int coefficient; //系数int exponent; //指数 node *next;};class polynomial //多项式{原创 2017-10-14 09:17:50 · 767 阅读 · 0 评论 -
数据结构 P38 算法实现 在带头结点的单链表的第i个元素插入元素e
/*算法2.20*/#includeusing namespace std;struct node //创建节点{int date; node *next;};class list //创建链表{int Length;原创 2017-10-11 21:22:03 · 11531 阅读 · 0 评论 -
数据结构 P36-37 算法实现 双向循环链表的插入与删除
/*双向链表的插入与删除*/#includeusing namespace std;struct node //双向链表的节点{int date;node *next; //指向后一个节点node *prior;原创 2017-10-11 16:00:02 · 804 阅读 · 0 评论 -
数据结构 P35 算法实现 双向循环链表的创建
#includeusing namespace std;struct node //双向链表的节点{int date;node *next; //指向后一个节点node *prior; //指向前一个节点};int main(){node *head,*s,*p,*q;//head—头结点 s—新节点 p—创建链表 q—打原创 2017-10-10 11:09:45 · 468 阅读 · 0 评论 -
数据结构 P31 算法实现 有序链表合并为有序链表
/*有序链表的合并 —算法2.12*/#includeusing namespace std;struct node //创建节点{int date;node *next;};class list //创建链表类{public:node *head,*s,*p;public: list(){hea原创 2017-10-05 20:59:58 · 336 阅读 · 0 评论 -
数据结构 P30 算法实现 链表的头插法 尾插法
#include#define OK 1#define ERROR 0int a,b;using namespace std; struct node{ int date; node *next; }; class List {node *head; public:List() {head=NULL;}原创 2017-09-30 16:05:00 · 310 阅读 · 0 评论 -
数据结构 P28-29 算法实现 线性表的链式存储结构——链表的查找、插入与删除
/*链表的创建与查找*/#includeusing namespace std;struct node{ int date; //数据域node *next; //指针域};int main(){ int x=1;node *head,*p; //定义头结点和节点head= new原创 2017-09-29 19:28:31 · 633 阅读 · 0 评论 -
数据结构 p25-26 算法实现 线性表的查找与归并排序2
/*线性表的查找 2.6*/#include using namespace std;#define SIZE 6int main(){int a[SIZE]={9,2,8,4,5,6};int elem,i,j=0;cin>>elem;for(i=0;i{ if (elem==a[i]){coutbreak;}}w原创 2017-09-25 16:39:54 · 604 阅读 · 0 评论 -
数据结构 P22-24 算法实现 线性表的插入与删除
/*线性表的插入*/#include using namespace std;#define LIST_INIT_SIZE 100 //线性表的初始分配量#define LISTINCREMENT 10 //线性表分配空间的增量 struct SqList //定义线性表结构体{i原创 2017-09-21 20:09:02 · 2047 阅读 · 0 评论 -
PAT-1015.反转链表(25)
感觉这是30道真题里最难的一道了,比其他25分的题主要难在它的陷阱太多,题目并没有明确指出,用了好久才AC,看到所有测试点都不红了,激动。经过多次尝试,总结的陷阱主要有 :1.看清题意!!!看清链表如何反转!!!2.首地址为-1的情况分类出来3.输出最后一个节点是next必须为-1.4.输入的节点中的无效节点不计入链表长度(节点地址无法与给定的首地址遍历下来的链表节点的next原创 2017-12-11 20:00:22 · 340 阅读 · 0 评论