Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Node {
- int x;
- Node *l,*r;
- };
- void add_node(int x,Node *&MyTree, int &k) {
- k++;
- if (NULL == MyTree) {
- MyTree = new Node;
- MyTree->x = x;
- MyTree->l = MyTree->r = NULL;
- }
- if (x < MyTree->x) {
- if (MyTree->l != NULL) add_node(x, MyTree->l, k);
- else {
- k++;
- MyTree->l = new Node;
- MyTree->l->l = MyTree->l->r = NULL;
- MyTree->l->x = x;
- }
- }
- if (x > MyTree->x) {
- if (MyTree->r != NULL) add_node(x, MyTree->r, k);
- else {
- k++;
- MyTree->r = new Node;
- MyTree->r->l = MyTree->r->r = NULL;
- MyTree->r->x = x;
- }
- }
- }
- int main() {
- Node *Tree = NULL;
- int x; cin >> x;
- vector<int>g(10000);
- while(x != 0) {
- int kol = 0;
- add_node(x,Tree, kol);
- g[kol - 1]++;
- cin >> x;
- }
- int n; cin >> n;
- cout << g[n];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement