oj-2找出可以感染者

#include
#include
#include
#include

using namespace std;

int search(int **table, int a[100], int N, int M, int T){
	setb;
	set::iterator iter;
	settmp_b;
	int index = 0;
	int i = 0, j = 0, k = 0;

	//第一层感染人群确认
	for (i = 0; i < M; i++)
	{
		for (j = 0; j < T; j++)
		{
			if (table[j][0] == a[i]){
				for (k = 0; k < M; k++){
					if (table[j][1] == a[k]) break;
				}
				if (k == M) b.insert(table[j][1]);
			}
			if (table[j][1] == a[i])
			{
				for (k = 0; k < M; k++)
				{
					if (table[j][0] == a[k]) break;
				}
				if (k == M) b.insert(table[j][0]);

			}
		}
	}
	for (iter = b.begin(); iter != b.end(); ++iter){
		tmp_b.insert(*iter);
	}
	
	//第二层感染人群确认
	for (iter = tmp_b.begin(); iter != tmp_b.end(); ++iter)
	{
		for (j = 0; j < T; j++)
		{
			if (table[j][0] == *iter){
				for (k = 0; k < M; k++){
					if (table[j][1] == a[k]) break;
				}
				if (k == M) b.insert(table[j][1]);
			}
			if (table[j][1] == *iter)
			{
				for (k = 0; k < M; k++)
				{
					if (table[j][0] == a[k]) break;
				}
				if (k == M) b.insert(table[j][0]);

			}
		}
	}

	//输出可疑感染人群
	for (iter = b.begin(); iter != b.end(); ++iter)
	{
		cout << *iter << " ";
	}
	
	return 0;
}


int main()
{
	int N = 0, M = 0, T = 0;
	int **table = NULL;
	int a[100];
	
	memset(a, 0, sizeof(a));
	cin >> N >> M >> T;

	table = new int *[T];
	for (int j = 0; j < T; j++)
	{
		table[j] = new int[2];	
	}
	
	for (int i = 0; i < M; i++)
	{
		cin >> a[i];	
	}

	for (int i = 0; i < T; i++){
		for (int j = 0; j < 2; j++){
			cin >> table[i][j];
		}
	}
	
	for (int i = 0; i < T; i++){
		for (int j = 0; j < 2; j++){
			cout << table[i][j] <<" ";
		}
		cout << endl;
	}

	search(table, a, N, M, T);

	if (table)
	{
		for (int j = 0; j < 2; j++)
		{
			delete[] table[j];
		}
		delete[]table;
	}
	
	return 0;
}

你可能感兴趣的:(C/C++,c++)