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的更多相关文章
随机推荐
- IOS开发中UITableView(表视图)的滚动优化及自定义Cell
IOS开发中UITableView(表视图)的滚动优化及自定义Cell IOS 开发中UITableView是非常常用的一个控件,我们平时在手机上看到的联系人列表,微信好友列表等都是通过UITable ...
- C++类的存储(部分可用与c的结构体)
c++中最重要的就是类,那么给你一个类的对象,你知道它在内存中如何存储的吗?它占内存中多少个字节? 首先确定类的构成: 1,数据成员:可以是内置类型,类类型. 2,函数成员:虚函数,非虚函数 1)数据 ...
- JavaScript------处理Json数据
//JSON相关函数 JSON.parse(); //将JSON字符串转换为JavaScript对象JSON.stringify(); //将JavaScript值转换为JSON字符串 1.//JSO ...
- python unicode 转中文 遇到的问题 爬去网页中遇到编码的问题
How do convert unicode escape sequences to unicode characters in a python string 爬去网页中遇到编码的问题 Python ...
- 在Cocos2d-x中实现较为真实的云彩效果
[前言] 这个效果是公司里上一个项目中用到的.因为项目已经死掉了,并且效果是我自己实现的,与其连着项目工程一起删掉,不如所以共产主义一下给大家作参考. 使用版本:cocos 2d-x 3.6(适用于所 ...
- 用控制台命令拉取git最新仓库代码
C#利用Diagnostics 拉取最新代码 示例代码 static void DiagnosticTest() { Process p; ProcessStartInfo psi; psi = ...
- PKU-1704-Georgia and Bob
题目链接 http://poj.org/problem?id=1704 这个题目是个好题,没有两下子是做不出的,其中考到,要你排序,如何把题目化成我们熟知的东西, 在这个题中我开始用选择法排序,他给我 ...
- Windows上的音频采集技术
在制作发布端的时候,需要采集到声卡的输出信号,以便与麦克风的输入信号进行混音,对于音频处理的技术,主要有如下几种: 采集麦克风输入 采集声卡输出 将音频数据送入声卡进行播放 对多路音频输入进行混音处理 ...
- vue原来可以这样上手
今儿与一群友讨论vue相关问题让我思量极深,1.我们是否在争对性解决问题或者说是帮助别人:2.我们是否在炫耀自己的技能.以下是被戏剧化的对白: "群友":最近按照vue官网示例学习 ...
- SQLSERVER如何导入数据保持ID不变(ID为自增主键)
使用SQL SERVER最操蛋的就是导入数据,以前用企业管理器直接导数据,导一次骂N次娘,在骂了微软无数次娘之后总结了一个方法揍合着还算受用. 其核心要点就是要将数据结构导入到目标数据库服务器上,再来 ...