摘要:View Code #include<IOSTREAM.H>#include <IOMANIP.H>#include <STRING.H>#include <STDLIB.H>//求两个字符串的最大公共子串//公共子串是指两个串中存在相同顺序的字符,但这些字符不必相邻/*int Length(int *array,char * A,int m,char *B,int n){ if (array[(strlen(B)+1)*m+n]<strlen(B)) return array[(strlen(B)+1)*m+n]; int temp; i
阅读全文
摘要:1装配线调度:一个汽车公司有两套装配线,每条装备线各有6个装配站,每个装配站完成装配需要一定的时间,两条装配线对应的站完成相同的功能,但所用的时间不一定相等。现在希望找出完成装配用的最少的装配站点。分析:经过第1条线的第N个装配站的最短的路径可能是从第一条线的第N-1个装配站送过去的,也可能由第二条线的第N-1个装配站送过去的,不管是从哪条线的第N-1个站送过来的,这个路径一定是经过该N-1站的最短路径,如果不是,那么就会有更短的路径从N-1站到达N装配站View Code #include<IOSTREAM.H>typedef struct Point{ int x;int y;
阅读全文
摘要:#include<iostream.h>typedef struct Element{ int index; int sum;}Element;void main(){ int array[]={-33,16,-48,5,16,-2,3,-11,10,-1}; Element elem; elem.index=0; elem.sum=array[0]; int temp=array[0]; for(int i=1;i<sizeof(array)/sizeof(int);i++) { if(temp<0) temp=0; ...
阅读全文
摘要:#include <IOSTREAM.H>#include <STDLIB.H>//二叉树的生成和释放typedef struct Node{ int data; struct Node * pParent; struct Node * pLeftChild; struct Node * pRightChild;}Node;Node * Create_BTree(int *array,Node* pParent=NULL)//二叉排序树的创建,按照先序遍历的方法进行构造{ static int i=0; if (array[i]==0) { ...
阅读全文
摘要:#include<iostream.h>#include<string.h>#include<stdlib.h>void main(){ char destr[]=" hello hello sfs che heloo dsljd hello hello "; int num=1; char *p=destr; while(*p!='\0') { if(*p>='A'&&*p<='Z') { *p=*p-'A'+'a'; } if(
阅读全文
摘要:#include <IOSTREAM.H>//计数排序,这是基数排序的基本操作//待排序的数字在某一范围内,如从0到9void main(){ int a[10]={0}; int array[]={2,3,4,2,3,5,2,9,8,6,5,0,1,7,6,8,9,5,3,6,7}; int temp[21]; for (int i=0;i<21;i++) { a[array[i]]++; } a[0]--; for(i=1;i<10;i++) a[i]+=a[i-1]; for (i=0;i<21;i++) ...
阅读全文
摘要:#include<iostream.h>//快速排序//起核心算法是划分子序列int Partition(int *a,int p,int r){ int x=a[p]; int i=p,j=r; while(true) { while(a[j]>x) j--; while(a[i]<x) i++; if(i<j) { if(a[i]==a[j]) //打破重复元素 j--; else ...
阅读全文
摘要:#include<iostream.h>//堆排序1,建堆,排序void Build_Heap(int *a,int length){ for(int i=1;i<length;i++) { int j=i; while(j-1>=0) { if(a[j]>a[(j-1)/2])//大于父节点,交换 { int temp=a[j];a[j]=a[(j-1)/2];a[(j-1)/2]=temp; j=(j-1)/2; ...
阅读全文
摘要:#include<iostream.h>void Merge(int *a,int p,int q,int r)//合并一个数组中前后两个有序序列{ //p,q,r是数组下标,a[p---q],a[q+1---r]两个有序 int *pA=a+p; int *pB=a+q+1; while(pA!=pB&&pB<=a+r) { if(*pA<=*pB) pA++; else { int temp=*pB; ...
阅读全文
摘要:#include <IOSTREAM.H>#include <MATH.H>#define LENGTH 8int num=0;int SuccessInsert(int (*a)[LENGTH],int x,int y){ for (int i=0;i<LENGTH;i++) { for (int j=0;j<LENGTH;j++) { if (a[i][j]==1&&(i==x||j==y||abs(x-i)==abs(y-j))) return 0; } } a[x][y...
阅读全文
摘要:#include<iostream.h>#include<string.h>void main(){ unsigned char b[1000000/8+1]; memset(b,0,1000000/8+1); int x=1000000-2; b[x/8]|=(1<<(x%8)); int y=b[x/8]; cout<<y<<endl;}
阅读全文