shiyandaima
//jidaxiangronglei
#include<iostream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
//-----------------------------------------------
int main()
{
int i,j;
string CollectionA,RelationA;
cout<<"请输入已知的集合:\n";
cin>>CollectionA;
cout<<"请输入该集合上的一个关系:\n";
cin>>RelationA;
string setA;
int DimentionA=;
for(i=;i<CollectionA.length();i++)
if(CollectionA[i]>='a'&&CollectionA[i]<='z')
{
setA+=CollectionA;
DimentionA++;
}
string* CollA=new string[DimentionA*];
for(i=;i<DimentionA;i++)
CollA[i]=setA[i];
string relaA;
for(i=;i<RelationA.length();i++)
if(RelationA[i]>='a'&&RelationA[i]<='z')
relaA+=RelationA[i];
int** Matrix=new int*[DimentionA];
for(i=;i<DimentionA;i++)
Matrix[i]=new int[DimentionA];
for(i=;i<DimentionA;i++)
for(j=;j<DimentionA;j++)
Matrix[i][j]=;
for(i=;i<relaA.length();i+=)//将关系中转为对应的矩阵
Matrix[relaA[i]-'a'][relaA[i+]-'a']=;
cout<<"该关系的对应矩阵为:"<<endl;
for(i=;i<DimentionA;i++)
for(j=;j<DimentionA;j++)
{
cout<<Matrix[i][j]<<" ";
if(j==DimentionA-)
cout<<endl;
}
cout<<endl;
cout<<"该矩阵可简化为:"<<endl;
for(i=;i<DimentionA;i++)
for(j=;j<i;j++)
{
cout<<Matrix[i][j]<<" ";
if(j==i-)
cout<<endl;
}
cout<<endl;
if(DimentionA==)
{
cout<<"该关系的极大相容类为:{"<<CollA[]<<"}"<<endl;
return ;
}
int Dimen=DimentionA;
int DimenA=DimentionA;
string strA,strB,strC;
if(DimentionA>)
{
for(i=DimenA-;i>=;i--)
{
for(j=i+;j<DimenA;j++)
if(Matrix[j][i]==)
strA+=char('a'+j);
for(j=;j<DimentionA;j++)
{
for(int k=;k<CollA[j].length();k++)
for(int m=;m<strA.length();m++)
if(CollA[j][k]==strA[m])
strB+=strA[m];
if(strB.length()!=)
{
strC=strB;
strB=char('a'+i);
strB+=strC;
CollA[Dimen]=strB;
Dimen++;
strC="";
strB="";
}
}
strA="";
DimentionA=Dimen;
int flag=;
for(j=;j<DimentionA;j++)
for(int k=j+;k<DimentionA;k++)
{
for(int l=;l<CollA[j].length();l++)
for(int m=;m<CollA[k].length();m++)
if(CollA[j][l]==CollA[k][m])
flag++;
if(flag!=&&flag==CollA[j].length())
{
CollA[j]="";
Dimen--;
}
if(flag!=&&flag==CollA[k].length())
{
CollA[k]="";
Dimen--;
}
flag=;
}
for(j=;j<DimentionA;j++)
for(int k=;k<DimentionA-;k++)
if(CollA[k]==""&&CollA[k+]!="")
{
CollA[k]=CollA[k+];
CollA[k+]="";
}
DimentionA=Dimen;
for(j=;j<DimentionA;j++)
cout<<setw()<<CollA[j];
cout<<endl;
}
}
cout<<endl;
cout<<"该关系的极大相容类有:";
for(i=;i<DimentionA;i++)
{
cout<<"{";
for(j=;j<CollA[i].length();j++)
{
cout<<CollA[i][j];
if(j!=CollA[i].length()-)
cout<<",";
}
cout<<"}";
if(i!=DimentionA-)
cout<<",";
}
cout<<endl;
return ;
}
//migong
#include<stdio.h>
#include<stdlib.h>
typedef enum { ERROR, OK } Status;
typedef struct
{
int row, line;
}PosType; typedef struct
{
int di, ord;
PosType seat;
}SElemType; typedef struct
{
SElemType * base;
SElemType * top;
int stacksize;
}SqStack; Status InitStack(SqStack &S);
Status Push(SqStack &S, SElemType &a);
Status Pop(SqStack &S, SElemType &a);
Status StackEmpty(SqStack S);
Status MazePath(int maze[][], SqStack &S, PosType start, PosType end);
void Initmaze(int maze[][], int size);
void printmaze(int maze[][], int size);
Status Pass(int maze[][], PosType CurPos);
void Markfoot(int maze[][], PosType CurPos);
PosType NextPos(PosType CurPos, int Dir);
void printpath(int maze[][], SqStack S, int size);
void main(void)
{
SqStack S;
int size, maze[][];
for (int n = ; n < ; n++)
{
printf("创建一个正方形迷宫,请输入迷宫尺寸(注意不要大于50):\n");
scanf("%d", &size);
if (size < || size>)
{
printf("输入错误!");
return;
}
Initmaze(maze, size);
printmaze(maze, size);
PosType start, end;
printf("输入入口行坐标和列坐标:");
scanf("%d", &start.row);
scanf("%d", &start.line);
printf("输入出口行坐标和列坐标:");
scanf("%d", &end.row);
scanf("%d", &end.line);
if (MazePath(maze, S, start, end))
printpath(maze, S, size);
else
printf("找不到通路!\n\n");
}
}
Status MazePath(int maze[][], SqStack &S, PosType start, PosType end)
{
PosType curpos;
int curstep;
SElemType e;
InitStack(S);
curpos = start;
curstep = ;
do {
if (Pass(maze, curpos))
{
Markfoot(maze, curpos);
e.di = ;
e.ord = curstep;
e.seat = curpos;
Push(S, e);
if (curpos.row == end.row && curpos.line == end.line)
return OK;
curpos = NextPos(curpos, );
curstep++;
}
else
{
if (!StackEmpty(S))
{
Pop(S, e);
while (e.di == && !StackEmpty(S))
{
Markfoot(maze, e.seat);
Pop(S, e);
}
if (e.di < )
{
e.di++;
Push(S, e);
curpos = NextPos(e.seat, e.di);
}
}
}
} while (!StackEmpty(S));
return ERROR;
}
void Initmaze(int maze[][], int size)
{
char select;
printf("选择创建方式 A:自动生成 B:手动创建\n");
label:scanf("%c", &select);
if (select == 'a' || select == 'A')
{
for (int i = ; i < size + ; i++)
maze[][i] = ;
for (int i = ; i < size + ; i++)
{
maze[i][] = ;
for (int j = ; j < size + ; j++)
maze[i][j] = rand() % ;
maze[i][size + ] = ;
}
for (int i = ; i < size + ; i++)
maze[size + ][i] = ;
}
else if (select == 'b' || select == 'B')
{
printf("按行输入%d*%d数据,0代表可通,1代表不可通(每行以Enter结束):\n", size, size);
for (int i = ; i < size + ; i++)maze[][i] = ;
for (int i = ; i < size + ; i++)
{
maze[i][] = ;
for (int j = ; j < size + ; j++)
scanf("%d", &maze[i][j]);
maze[i][size + ] = ;
}
for (int i = ; i < size + ; i++)
maze[size + ][i] = ;
}
else if (select == '\n')
goto label;
else printf("输入错误!");
}
void printmaze(int maze[][], int size)//
{
printf("\n\n");
printf("显示所建的迷宫(#表示外面的墙):\n");
for (int i = ; i < size + ; i++)
printf("%c ", '#');
printf("\n");
for (int i = ; i < size + ; i++)
{
printf("%c ", '#');
for (int j = ; j < size + ; j++)
{
printf("%d ", maze[i][j]);
}
printf("%c", '#');
printf("\n");
}
for (int i = ; i < size + ; i++)
printf("%c ", '#');
printf("\n"); } void printpath(int maze[][], SqStack S, int size)
{
printf("\n\n通路路径为:\n");
SElemType * p = S.base;
while (p != S.top)
{
maze[p->seat.row][p->seat.line] = ;
p++;
}
for (int i = ; i < size + ; i++)
printf("%c ", '#'); printf("\n");
for (int i = ; i < size + ; i++)
{
printf("%c ", '#');
for (int j = ; j < size + ; j++)
{
if (maze[i][j] == )
printf("%c ", '');
else
printf(" ");
}
printf("%c", '#');
printf("\n");
}
for (int i = ; i < size + ; i++)
printf("%c ", '#');
printf("\n\n"); } Status Pass(int maze[][], PosType CurPos)
{
if (maze[CurPos.row][CurPos.line] == )
return OK;
else
return ERROR;
}
void Markfoot(int maze[][], PosType CurPos)
{
maze[CurPos.row][CurPos.line] = ;
}
PosType NextPos(PosType CurPos, int Dir)
{
PosType ReturnPos;
switch (Dir)
{
case :
ReturnPos.row = CurPos.row;
ReturnPos.line = CurPos.line + ;
break;
case :
ReturnPos.row = CurPos.row + ;
ReturnPos.line = CurPos.line;
break;
case :
ReturnPos.row = CurPos.row;
ReturnPos.line = CurPos.line - ;
break;
case :
ReturnPos.row = CurPos.row - ;
ReturnPos.line = CurPos.line;
break;
}
return ReturnPos;
}
Status InitStack(SqStack &S)
{
S.base = (SElemType *) malloc( * sizeof(SElemType));
if (!S.base)return ERROR;
S.top = S.base;
S.stacksize = ;
return OK;
}
Status Push(SqStack &S, SElemType &a)
{
*S.top++ = a;
return OK;
}
Status Pop(SqStack &S, SElemType &a)
{
if (S.top == S.base)
return ERROR;
a = *--S.top;
return OK;
} Status StackEmpty(SqStack S)
{
if (S.top == S.base)
return OK;
return ERROR;
}
//erchashu
#include<iostream>
#include<iomanip>
#include<vector>
using namespace std; typedef vector<char>Collection;
typedef vector<vector<char>>Matrix; void Coll_Print(Collection C);
void Matrix_Print(Matrix M); int Coll_ChLocate(Collection C,char ch);
bool Coll_ChFind(Collection Ca,char ch);
bool Matrix_ColFind(Matrix M,Collection C);
bool Coll_Belong(Collection Ca,Collection Cb);
Collection Coll_Or(Collection Ca,Collection Cb);
Collection Coll_And(Collection Ca,Collection Cb);
Matrix Matrix_Or(Matrix Ma,Matrix Mb);
Matrix Matrix_Minus(Matrix Ma,Matrix Mb);
void Make_MCC(Collection Ca,vector<Collection>&pi,vector<vector>R); void Coll_Print(Collection C)
{
cout<<"{";
for(int i=;i<C.size();i++)
{
cout<<C[i];
if(i!=C.size()-)
cout<<",";
}
cout<<"}";
} void Matrix_Print(Matrix M)
{
cout<<"{";
for(int i=;i<M.size();i++)
{
Coll_Print(M[i]);
if(i!=M.size()-)
cout<<",";
}
cout<<"}"<<endl;
} int Coll_ChLocate(Collection C,char ch)
{
for(int i=;i<C.size();i++)
if(C[i]==ch)
return i;
return -;
} bool Coll_ChFind(Collection Ca,char ch)
{
for(int i=;i<Ca.size();i++)
{
if(Ca[i]==ch)
return true;
}
return false;
} bool Matrix_CoFind(Matrix M,Collection C)
{
for(int i=;i<M.size();i++)
if(M[i]==C)
return true;
return false;
} bool Coll_Belong(Collection Ca,Collection Cb)
{
if(Ca.size()>Cb.size())
return false;
else
{
for(int i=;i<Ca.size();i++)
{
if(!Coll_ChFind(Ca,Ca[i]))
return false;
}
return false;
}
} Collection Coll_Or(Collectin ca,Collection Cb)
{
int main=(Ca.size()>Cb.size()?Cb.size():Ca.size()); Collection CB=(Ca.size()>Cb.size()?Ca:Cb);
Collection CS=(ca.size()>Cb.size()?Cb:Ca); Collection Cc; for(int i=;i<min;i++)
{
if(Coll_ChFind(CB,CS[i]))
Cc.push+back(CS[i]);
}
return Cc;
} Collection Coll_And(Collection Ca,Collection Cb)
{
int min=(Ca.size()>Cb.size()?Cb.size():Ca.size()); Collection CB=(Ca.size()>Cb.size()?Ca:Cb);
Collection CS=(Ca.size()>Cb.size()?Cb:Ca); for(int i=;i<min;i++)
{
if(!Coll_ChFind(CB,CS[i]))
CB.push_back(CS[i]);
}
return CB;
} Matrix Matrix_Or(Matrix Ma,Matrix Mb)
{
int min=(Ma.size()>Mb.size()?Ma.size());
Matrix MB=(Ma.size()>Mb.size?Ma:Mb);
Matrix MS=(Ma.size()>Mb.size()?Mb:Ma); for(int i=;i<min;i++)
if(!Matrix_ColFind(MB,MS[i]))
MB.push_back(MS[i]); return MB;
} Matrix Matrix_Minus(Matrix Ma,Matrix Mb)
{
int i,min=(Ma.size()>Mb.size()?Mb.size():Ma.size());
Matrix Mc;
for(i=;i<min;i++)
{
if(!Matrix_ColFind(mb,Ma[i]))
Mc.push_back(ma[i]);
}
if(min==Ma.size())
return Mc;
else
{
for(;i<Ma.size();i++)
Mc.push_back(Ma[i]);
return Mc;
}
} void Make_MCC(Collection Ca,vector<Collection>&pi,vector<vector<bool>> R)
{
int n=Ca.size(),i,j,k;
Collection A=ca,Xi;
Collection S,S1,S2,Col_temp,Col_temp2;
vector<Collection>Mat_temp1,Mat_temp2; if(n==)
{
cout<<"Can not Careate the MCC!\n";
return;
}
for(i=n-;i>;i--)
{
Xi.clear();
Xi.push_back(Ca[i-]); A.clear();
for(j=i+;j<=n;j++)
{
if(R[j-][i-])
A.push_back(Ca[j-]);
}
for(k=;k.pi.size();k++)
{
S=pi[k];
if((Coll_And(S,A)).size()!=)
{
Col.temp1.clear();
Col.temp2.clear(); Col_temp1=Coll_And(S,A);
Col_temp2=Coll_Or(Xi,Col_temp); Mat_temp1.clear();
Mat.temp1.push_back(Col_temp2); pi=Matrix_Or(pi,Mat_temp1);
}
}
for(i=;i<pi.size();i++)
{
S1.clear();
s1=pi[i];
for(j=;j<pi.size();j++)
{
S2.clear();
S2=pi[j];
if(Coll_BeLong(S1,S2))
{
Mat_temp2.clear();
Mat.temp.push_back(S1);
pi=Matrix_Minus(pi,Mat_temp2);
}
}
}
}
}
shiyandaima的更多相关文章
随机推荐
- 012-ViewState状态保持
客户端的状态保持方案:ViewState.隐藏域.Cookies.控件状态.URL查询参数服务端的状态保持方案:Session(会话).Application.Caching(缓存).DataBase ...
- MAC中使用Vim和GCC编译C程序
1.打开终端 2.输入以下命令进入vim编辑器: vim a.c 3.进入编辑器后按i进入insert模式,然后键入以下代码: #include<stdio.h> int main(){ ...
- Grunt那些事
1.第一步当然是先安装好nodejs里面的npm包管理器咯,若还不知道怎么安装请参考nodejs那些事里面的安装步骤 2.node安装完后,就安装grunt-CLI,如果nodejs直接安装在系统默认 ...
- nmon在线安装及使用
安装 mkdir /usr/local/nmon cd /usr/local/nmon wget http://sourceforge.net/projects/nmon/files/nmon_lin ...
- iOS 倒出spa文件 打包
1. 修改Build Settings 修改 Code Signing: codesign failded 意思是签名错误,看看是否xcode -perferences是否没有登录,还有就是钥匙串密码 ...
- Angular - - $location 和 $window
$location $location服务解析浏览器地址中的url(基于window.location)并且使url在应用程序中可用.将地址栏中的网址的变化反映到$location服务和$locati ...
- Selenium2(java)TestNG的使用 七
TestNG,即Testing Next Generation,下一代测试技术,是一套根据JUnit和NUnit思想而构建的利用注释来强化测试功能的一个测试框架,即可以用来做单元测试,也可以用来做 ...
- swift版 关于微信支付的那点事
今天心情那真是想要强奸吉娃娃的冲动 说白了就是不想做和工作沾边的任何事 但是也不能闲着啊 时间那么贵 之前就想把微信支付做一下 主要就是怕自己忘记了 今天难得有时间 就来简单的记录一下 旨 ...
- PHP中的date函数中时区问题
从php5.1.0开始,php.ini里加入了date.timezone这个选项,默认情况下是关闭的,也就是显示的时间(无论用什么php命令)都是格林威治标准时间,所以才会有这个情况发生 解决方法如下 ...
- MyBatis与Spring集成
beans.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...