Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <queue>
- using namespace std;
- /*
- Список студентів
- sdudent 12
- Adam 9
- Nikol 2
- Dio 13
- Kostya 20
- Bohdan 20
- Roma 10
- Kia 2
- */
- //структура
- struct City{
- string nameCity = "";
- string region = "";
- };
- void read_file(queue<City> &q, string path){
- queue<City> more_ten; //для больше 10
- queue<City> nine_or_ten; // для 10 или 9
- queue<City> two; // для 2
- ifstream info_students(path);
- string line;
- City student;
- stringstream ss;
- while(getline(info_students, line)){
- ss << line;
- ss >> student.nameCity;
- ss >> student.region;
- if(student.region == "Ki"){
- more_ten.push(student);
- }
- else if(student.region == "Kiv"){
- nine_or_ten.push(student);
- }
- else{
- two.push(student);
- }
- ss.clear();
- }
- //вывод! для больше 10
- while(!more_ten.empty()){
- q.push(more_ten.front());
- more_ten.pop();
- }
- //вывод! для 10 или 9
- while(!nine_or_ten.empty()){
- q.push(nine_or_ten.front());
- nine_or_ten.pop();
- }
- //вывод! для 2
- while(!two.empty()){
- q.push(two.front());
- two.pop();
- }
- }
- /**
- * Вывод!
- * @param q что вывести
- */
- void print_queue(queue<City> q){
- while(!q.empty()){
- cout << "Name : " << q.front().nameCity << endl
- << "Score : " << q.front().region << endl << endl;
- q.pop();
- }
- }
- int main()
- {
- queue<City> students_info;
- read_file(students_info, "..\\tess.txt");
- print_queue(students_info);
- }
Advertisement
Add Comment
Please, Sign In to add comment