关注
//用弗洛伊德算法思想
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
vector<int> label;
vector<int> dataIndex;
void AddDependency(unsigned int Moduled, unsigned int DeModuled)
{
for(int i = 0; i < label.size(); ++i)
{
if(Moduled == label[i])
{
dataIndex.push_back(Moduled);
break;
}
}
for(int j = 0; j < label.size(); ++j)
{
if(DeModuled == label[j])
{
dataIndex.push_back(DeModuled);
break;
}
}
}
int main()
{
vector<string> input;
vector<int> result;
string temp;
while(getline(cin, temp))
{
input.push_back(temp);
}
int len = input.size();
for(int i = 0; i < len; i++)
{
temp = input[i];
int k = 3;
int num = 0;
while(temp[k] != ',')
{
if(temp[k] >= '0' && temp[k] <= '9')
{
num = num * 16 + temp[k] - '0';
k++;
}
else
{
num = num * 16 + temp[k] - 'a';
k++;
}
}
result.push_back(num);
num = 0;
k = k + 4;
while(temp[k] != '}')
{
if(temp[k] >= '0' && temp[k] <= '9')
{
num = num * 16 + temp[k] - '0';
k++;
}
else
{
num = num * 16 + temp[k] - 'a';
k++;
}
}
result.push_back(num);
num = 0;
}
/*
vector<int> time;
vector<int> duitime;
map<int, int> Hash;
for(int i = 0; i < result.size()-1; i += 2)
{
++Hash[result[i+1]];
}
map<int, int>::iterator mapi;
for(mapi = Hash.begin(); mapi != Hash.end(); mapi++)
{
int a = mapi->first;
int b = mapi->second;
duitime.push_back(a);
time.push_back(b);
}
*/
vector<int> result_temp(result);
sort(result_temp.begin(), result_temp.end());
label.push_back(result_temp[0]);
for(int i = 1; i < result_temp.size(); i++)
{
if(result_temp[i] != result_temp[i-1])
label.push_back(result_temp[i]);
}
/*
for(int i = 0; i < label.size(); i++)
cout << label[i] << endl << endl;
*/
for(int i = 0; i < result.size()-1; i += 2)
{
AddDependency(result[i], result[i+1]);
}
/*
for(int i = 0; i < dataIndex.size(); i++)
cout << dataIndex[i] << endl;
*/
int **arr = new int*[label.size()];
for(int i = 0; i < label.size(); i++)
arr[i] = new int[label.size()];
//初始化数组为全0;
for(int i = 0; i < label.size(); i++)
for(int j = 0; j < label.size(); j++)
arr[i][j] = 0;
for(int i = 0; i < result.size()-1; i += 2)
{
arr[dataIndex[i]-1][dataIndex[i+1]-1] = 1;
}
/*
for(int i = 0; i < label.size(); i++)
{
for(int j = 0; j < label.size(); j++)
cout << arr[i][j] << ' ';
cout << endl;
}
cout << endl;
*/
for(int i = 0; i < label.size(); i++)
{
for(int j = 0; j < label.size(); j++)
{
for(int k = 0; k < label.size(); k++)
{
if(arr[j][i] == 1 && arr[i][k] == 1)
{
arr[j][k] = 1;
}
}
}
}
/*
for(int i = 0; i < label.size(); i++)
{
for(int j = 0; j < label.size(); j++)
cout << arr[i][j] << ' ';
cout << endl;
}
cout << endl;
*/
//输出的格式没有调
for(int i = 0; i < label.size(); ++i)
{
if(arr[i][i] == 1)
cout << label[i] << endl;
}
//最后需要释放内存
return 0;
}
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 26届秋招公司红黑榜 #
4356次浏览 11人参与
# 实习必须要去大厂吗? #
144812次浏览 1521人参与
# 平安产险科技校招 #
2062次浏览 0人参与
# 校招泡的最久的公司是哪家? #
1392次浏览 9人参与
# 你觉得mentor喜欢什么样的实习生 #
5499次浏览 178人参与
# 入职第一天,你准备什么时候下班 #
84606次浏览 464人参与
# 智慧芽求职进展汇总 #
9146次浏览 73人参与
# 技术岗笔试题求解 #
94858次浏览 1101人参与
# 没有家庭托举的我是怎么找工作的 #
7129次浏览 107人参与
# 最难的技术面是哪家公司? #
54056次浏览 891人参与
# 度小满求职进展汇总 #
8145次浏览 42人参与
# 从哪些方向判断这个offer值不值得去? #
3520次浏览 74人参与
# 求职低谷期你是怎么度过的 #
3047次浏览 65人参与
# 秋招想进国企该如何准备 #
97120次浏览 487人参与
# 你有哪些缓解焦虑的方法? #
36672次浏览 835人参与
# 工作压力大怎么缓解 #
117132次浏览 1108人参与
# 独居后,你的生活是更好了还是更差了? #
27637次浏览 263人参与
# 机械人的工作环境真的很差吗 #
24249次浏览 118人参与
# 我对___祛魅了 #
134653次浏览 744人参与
# 哪些瞬间让你真切感受到了工作的乐趣 #
15086次浏览 70人参与
# 我的求职进度条 #
143225次浏览 1629人参与
# 打工人的工作餐日常 #
69661次浏览 505人参与