用C++实现warshall的算法

#include
void warshall(char *[],int size);//声明一个函数
void main()//主函数
{
 int size=0;
 cout<<"Input number of dimensions:";
 cin>>size;//输入矩阵的大小
 cout<<"Input elements:";
 char**args=new char*[size];//定义个二维字符串数组
 char c;
 for(int l=0;l {
  cout<<"Input the element of "<  args[l]=new char[size];/
  for(int j=0;j  {
   cin>>c;
   args[l][j]=c;
  }
 }
 warshall(args,size);//调用这个函数
}
void warshall(char *args[],int size)//warshall算法的实现
{
 for(int i=0;i {
  for(int j=0;j  {
   if(args[j][i]=='1')//找每列为1的元素
   {   
    for(int k=0;k    {
    if(args[i][k]=='1'||args[j][k]=='1')//算法
        args[j][k]='1';   
     
    }
   }
  }
 }
 cout<<"after caculator with warshall :"< for(int l=0;l {
  for(int j=0;j  {cout<  cout< }
 
}
 

你可能感兴趣的:(用C++实现warshall的算法)