#include<bits/stdc++.h>
using namespace std;

struct Book{
	string ten;
	int sotrang;
};

struct Node{
	Book data;
	Node *next;
	Node(string t, int st){
		data.ten = t;
		data.sotrang = st;
		next = nullptr;
	}
};

void addB(Node *&head, string t, int st){
	Node *newNode = new Node(t, st);
	if(head == nullptr){
		head = newNode;
		return;
	}
	Node *temp = head;
	while(temp->next != nullptr){
		temp = temp->next;
	}
	temp->next = newNode;
}

void printB(Node *head){
	Node *temp = head;
	if(head == nullptr){
		cout << "Rong!" << endl;
		return;
	}
	while (temp != nullptr){
		cout << temp->data.ten << "\t - \t" << temp->data.sotrang << endl;
		temp = temp->next;
	}
}

int countT(Node *head){
	Node *temp = head;
	int dem = 0;
	while(temp != nullptr){
		if(temp->data.sotrang > 500){
			dem++;
		}
		temp = temp->next;
	}
	return dem;
}

void deleteB(Node *&head){
	Node *temp = head;
	int nho = temp->data.sotrang;
	while(temp != nullptr){
		if(nho > temp->data.sotrang){
			nho = temp->data.sotrang;
		}
		temp = temp->next;
	}
	while (head != nullptr && head->data.sotrang == nho){
		Node *xoa = head;
		head = head->next;
		delete xoa;
	}
	Node *tam = head;
	while(tam != nullptr && tam->next != nullptr){
		if(tam->next->data.sotrang == nho){
			Node *xoa = tam->next;
			tam->next = tam->next->next;
			delete xoa;
		} else {
			tam = tam->next;
		}
	}
}

int main(){
	Node *head = nullptr;
	cout << "-----Danh sach sach-----" << endl;
	addB(head, "Doraemon", 200);
	addB(head, "Toan Roi Rac", 750);
	addB(head, "Doraemon", 200);
	addB(head, "Giai tich 1", 200);
	addB(head, "Toan Logic", 300);
	addB(head, "Tieng Viet", 1750);
	printB(head);
	cout << endl << "So sach lon hon 500 trang: ";
	cout << countT(head);
	deleteB(head);
	cout << endl << "Sau khi xoa so trang nho nhat!" << endl;
	printB(head);
	return 0;
}