摘要: 这个没有仔细考虑过!算法也没想过!哎!、算法问题(任选一题)。 (1) 皇后问题:在国际象棋中,能否在空棋盘上摆放八个皇后,并使其中任意两个皇后 不能在同一行或同一列或同一对角线上,并编写完整的摆放八皇后问题的程序。要求: 第一个皇后的起始位置由键盘输入,国际象棋的棋盘为8*8 的方格。 (2) 迷宫问题,用数组方式实现一个迷宫。 阅读全文
posted @ 2009-06-26 16:26 CMuYu 阅读(116) 评论(0) 推荐(0)
摘要: #include <iostream>#include <cmath>using namespace std;int main(){ int a[100],i,m=0,n,x; cout<<"请输入长整数的位数:"; cin>>a[0]; cout<<"从高位到低位分别输入长整数的数字,每位以空格间隔:"; for(i=a[0];i>=1;i--) cin>>a[i]; for(i=1;i<=a[0];i++) m=m+a[i]*pow(10,i-1); cout< 阅读全文
posted @ 2009-06-26 16:25 CMuYu 阅读(141) 评论(0) 推荐(0)
摘要: #include <iostream>#include <cmath>#include <stdio.h>using namespace std;int main(){ int a[100],i,m=0,n,b[100],c[100],z; cout<<"请输入长整数的位数:"; cin>>a[0]; cout<<"从高位到低位分别输入长整数的数字,每位以空格间隔:"; for(i=a[0];i>=1;i--) cin>>a[i]; for(i=1;i<=a[ 阅读全文
posted @ 2009-06-26 16:23 CMuYu 阅读(116) 评论(0) 推荐(0)
摘要: #include <iostream>#include <iomanip>using namespace std;bool runian(int x){ if(x%400==0||x%4==0&&x%100!=0) return true; else return false;}int main(){ int x,y,h,i,j=0; cout<<"请输入年份:"; cin>>h; if(h<2000) { for(i=h;i<2000;i++) { if(runian(i)) j++; } j=6 阅读全文
posted @ 2009-06-26 16:21 CMuYu 阅读(179) 评论(0) 推荐(0)
摘要: #include <iostream>#include <iomanip>using namespace std;int main(){ int i=0,j=0,a=1,u,n; int lx[100][100]; cout<<"请输入方阵的行列数:"; cin>>n; for(u=0;u<n/2;u++) { for(j=u;j<n-u;j++) { lx[i][j]=a; a++; } j=j-1; for(i=u+1;i<n-u;i++) { lx[i][j]=a; a++; } i=i-1; for( 阅读全文
posted @ 2009-06-26 16:19 CMuYu 阅读(174) 评论(0) 推荐(0)
摘要: #include <iostream>#include <fstream>#include <cstring>#include <string>using namespace std;int main(){ char st[100],a,k,b[20],c[20]; int n,j=0,i,m,h[10]; ofstream out_file("e://sh.txt",ios::out); if(!out_file) exit(-1); cout<<"请输入一段英文句子:"; gets(st); 阅读全文
posted @ 2009-06-26 16:17 CMuYu 阅读(161) 评论(0) 推荐(0)
摘要: #include <iostream>#include <cstring>#include <string>using namespace std;int main(){ int n,c,i,j,h[10]; //n用来存储字符串长度,i j用来计数,h存放查找的字符串出现的位置 char st[100],s,z[20],x[20],m; //s在空格转换和判断是否是用到,m判断是用到,z x用来存放要查询的字符串 cout<<"请输入一段英文句子:"; gets(st); n=strlen(st); while(st[n-1 阅读全文
posted @ 2009-06-26 16:14 CMuYu 阅读(182) 评论(0) 推荐(0)
摘要: #include <iostream>#include <ctime>#include <cstdlib>using namespace std;int main(){ int x,y,z,i,l,b,a,c=0; char h; cout<<"是否要进行测试?(y/n):"; cin>>h; //srand(time(null)); while(h=='y') { do {cout<<"请选择要测试的类型(1:加法;2:减法;3:乘法):"; cin>> 阅读全文
posted @ 2009-06-26 16:12 CMuYu 阅读(142) 评论(0) 推荐(0)
摘要: #include <iostream>using namespace std;class student{ int number; char name[10]; int computer,math,english,physics; public: bool eq(int n) { if(number==n) return true; else return false; } void dele() { number=-1; } void input() { cout<<"学号:"; cin>>number; cout<<&qu 阅读全文
posted @ 2009-06-26 16:08 CMuYu 阅读(149) 评论(0) 推荐(0)
摘要: #include<iostream>using namespace std;#define N 8 //改成8就是八皇后了class Queen{ friend int nQueen(int); private: void Print(int x[]); bool Place(int k); void Backtrack(int t); int n, *x; long sum;};bool Queen::Place(int k){ int j; for(j=1;j<k;j++) if((abs(k-j)==... 阅读全文
posted @ 2009-06-26 16:05 CMuYu 阅读(177) 评论(0) 推荐(0)
摘要: #include <iostream>using namespace std;bool hang(char xq[][9],int x) //行是否被攻击{ for(int u=0;u<8;u++) { if(xq[x][u]=='*') break; } if(xq[x][u]=='*') return false; else return true;}bool lie(char xq[][9],int y) //列{ for(int o=0;o<8;o++) { if(xq[o][y]=='*') break; } i 阅读全文
posted @ 2009-06-26 15:56 CMuYu 阅读(178) 评论(0) 推荐(0)