signed

QiShunwang

“诚信为本、客户至上”

其它

2021/3/21 8:55:11   来源:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int f[1005], d[1005];
int n, m;

int main() {
	cin >> n >> m;
	
	int x, y;
	while (m--)	 {
		cin >> x >> y;
		f[y] = x;
		d[x] ++ ;
	}
	
	for (int i = 0; i <= 1000; i++ ) {
		if (f[i]==0 && d[i]>0)  cout << i << endl;
	}
	
	int max = 0;
	for (int i = 0; i <= 1000; i ++ ) {
		if (d[i] > d[max]) max = i;
	}
	cout << max << endl;
	
	for (int i = 0; i <= 1000; i ++ ) {
		if (f[i] == max) cout << i << ' ';
	}

	return 0;
}

1367:查找二叉树(tree_a)

#include <cstdio>
#include <iostream>
using namespace std;

int n, x, cnt;

struct node{
	int val, l, r;
}a[105];

void f(int n) {
	if (n == 0) return;
	
	f(a[n].l);
	
	cnt ++ ;
	if (a[n].val == x) {
		cout << cnt ;
	}
	
	f(a[n].r);	
}

int main() {
	cin >> n >> x;
	
	for (int i = 1; i <= n; i ++ ) {
		cin >> a[i].val >> a[i].l >> a[i].r;
	}

	f(1);
	
	return 0;
}