c/c++
文章平均质量分 68
王维_ICT
这个作者很懒,什么都没留下…
展开
-
八皇后问题求解1
#include using namespace std; int col[8],Left[15],Right[15]; int queen[8]; int n=0; int sum=0; void generate() { int h,i; for(h=0;h { if(col[h]&& Left[n+h] && Right[n-h+7]) {原创 2010-08-12 16:03:00 · 407 阅读 · 0 评论 -
打发无聊时间
<br />一、 倒序数是将一个阿拉伯数的各位上的数字以逆序的形式写成的数。该阿拉伯数的第一位变成最后位,最后位变成第一位。例如数1245被写成5421。注意产生的新数字前边所有的数字0是被略去的。倒序数的尾部无多余的数字0。请将阿拉伯数转变为倒序数。<br />输入<br />输入的第一行仅有一个正整数n,表示有n组测试数据。接下来有n行,每一行是一组测试数据,长度不超过100。每一行上的字符串表示一个非负整数,它是你需要转换的数。<br />输出<br />对每一组测试数据在一行上输出倒序数,该倒序数中原创 2011-04-25 18:48:00 · 811 阅读 · 0 评论 -
图操作 && help pro_lee
matrix_path.c#include #include #define MAXLEN 10 typedef struct { char vexs[MAXLEN]; int edges[MAXLEN][MAXLEN]; int n, e; }MGraph; typedef struct { char *ss; int top; int bottom; int len; }stack; typedef struct { int* que;原创 2011-04-22 18:52:00 · 428 阅读 · 0 评论 -
funny program
<br /> <br />#define __ a #define ___ main( #define ____ printf( #define _____ char __[] ={ #define ______ };____"%s", __ #define _______ _____ 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 0 #define _ ___){ _______ ______);} #include转载 2011-04-06 13:11:00 · 1353 阅读 · 0 评论 -
汉诺塔问题
<br />#include<stdio.h><br />#include<stdlib.h><br />int c;<br />void move(char a,int n,char b)<br />{<br /> printf("%d:/tmove disk %d from %c to %c/n",++c,n,a,b);<br />}<br />void hanoi(int n,char x,char y,char z)<br />{<br /> if(n==1) move(x,1,z);<br />原创 2010-09-24 22:13:00 · 369 阅读 · 0 评论 -
二叉排序树的建立和遍历
<br />#include<stdio.h><br />#include<stdlib.h><br /> <br />typedef struct node{<br /> int data;<br /> struct node *left,*right;<br />}node;<br /><br />node *create(node *tree,int n)<br />{<br /> node *p=(node *)malloc(sizeof(node));<br />原创 2010-09-13 21:34:00 · 398 阅读 · 0 评论 -
建立链表
<br />循环建立链表:<br /> <br />#include<stdio.h><br />#include<stdlib.h><br />typedef struct node{<br /> int data;<br /> struct node *next;<br />}node;<br />void main()<br />{<br /> node *head=NULL,*tail,*p;<br /> int i,*a;<br /> a=(int原创 2010-09-09 21:23:00 · 344 阅读 · 0 评论 -
约瑟夫问题
<br />#include<iostream> <br />using namespace std; <br /><br /><br />void main() <br />{<br /> int n,m,a[101],k,i,j,num; //计数器是从1开始的,所以100个人用101<br /> cout<<"请输入参加游戏的玩家人数(不超过100人):";<br /> cin>>n;<br /> cout<<"--------------------------转载 2010-08-22 21:29:00 · 304 阅读 · 0 评论 -
24点算法2
#include<iostream> #include<string.h> using namespace std; double a[7],r[7]; bool okay,used[7]; double op(double a,long x,double b) { switch(x) { case 1:return a+b; case 2:return a-b;转载 2010-08-13 10:34:00 · 682 阅读 · 0 评论 -
24点算法实现
#include <fstream> #include <algorithm> #include <string> #include <sstream> #include <list> #include <cmath> #include <climits> #include <bitset> using namespace std; const char* INPUT_FILE = "game.in"; const char* OUTPUT_FILE = "gam转载 2010-08-13 10:33:00 · 671 阅读 · 0 评论 -
C语言动态内存分配函数解析
<br /> 引言:对于指针,正确的分配动态内存 是十分重要的,本文将着重阐述动态内存分配函数malloc,calloc,realloc以及memset的用法。 <br /> 一、对于malloc,在终端输入 #:man malloc可以知道函数原型是:<br /> Void *calloc(size_t size) ,包含在库函数 stdlib.h中,作用是在内存的堆区分配一个大小为size的连续空间,如果分配内存成功,函数返回新分配内存的首地址,否则,返回NULL ,注意:鉴于上述转载 2010-08-12 16:48:00 · 867 阅读 · 0 评论 -
最长公共子序列的长度
<br />动态规划算法可有效地解此问题。下面我们按照动态规划算法设计的各个步骤来设计一个解此问题的有效算法。<br /> 1.最长公共子序列的结构<br /><br /> 解最长公共子序列问题时最容易想到的算法是穷举搜索法,即对X的每一个子序列,检查它是否也是Y的子序列,从而确定它是否为X和Y的公共子序列,并且在检 查过程中选出最长的公共子序列。X的所有子序列都检查过后即可求出X和Y的最长公共子序列。X的一个子序列相应于下标序列{1, 2, …, m}的一个子序列,因此,X共有2m个不同子序列,从转载 2010-08-12 16:29:00 · 1233 阅读 · 0 评论 -
关于静态存储区域,堆,栈
<br /> 有关动态对象创建:一般来说,编译器将内存分为三部分:静态存储区域、栈、堆。静态存储区主要保存 全局变量和静态变量,栈存储调用函数相关的变量、地址等,堆存储动态生成的变量,在c中是指由malloc,free运算产生释放的存储空间,在c++中 就是指new和delete运算符作用的存储区域。<br />1、 静态存储分配<br />指在编译时对数据对象分配固定的存储位置,运行时始终不变。即一旦存储空间的某个位置分配给了某个数据名,则在目标程序的整个运行过程中,此位置(地址)就属于该数据名转载 2010-08-12 15:43:00 · 528 阅读 · 0 评论 -
八皇后问题求解2
<br />#include<iostream><br /> #include<vector><br /> #include<algorithm><br /> using namespace std;<br /> const int n=8;<br /> string solu;<br /> vector<string> solus;<br /><br /> int column[n];<br /> int left11[2*n-1];<br /> int right11[2*n-1];<转载 2010-08-12 16:08:00 · 270 阅读 · 0 评论 -
排序
归并排序: #include #include void display(int d[],int n) { int i; for(i=0;i printf("%d/t",d[i]); printf("/n"); } void merge(int u[],int v[],int w[],int m,int n) { int i,j,k; i=j=k=0;原创 2010-09-24 21:42:00 · 280 阅读 · 0 评论