Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <fstream>
- #include <vector>
- #include <iterator>
- #include <string>
- #include <sstream>
- #include <algorithm>
- using namespace std;
- class Record {
- public:
- int score;
- string name;
- Record(int score, const string &name) : score(score), name(name) {}
- };
- using namespace std;
- int main() {
- vector<Record*> test;
- ifstream in("test.txt");
- string teststr;
- while (!in.eof()) {
- getline(in, teststr);
- std::size_t pos = teststr.find(":");
- string s2 = teststr.substr(pos+1, 13);
- string s3 = teststr.substr(0, pos);
- std::istringstream ist(s3);
- int hey = 0;
- ist >> hey;
- if (hey == 0) {
- break;
- }
- else {
- test.push_back(new Record(hey, s2));
- }
- }
- test.push_back(new Record(25000, "A")); // Добавление значений
- test.push_back(new Record(15000, "B"));
- test.push_back(new Record(45000, "C"));
- test.push_back(new Record(44999, "Hai"));
- //sort(test.rbegin(), test.rend());
- for (int i = 0; i < test.size()-1; i++) {
- for (int j = 0; j < test.size() - i - 1; j++) {
- if (test[j]->score < test[j+1]->score) {
- int temp = test[j]->score;
- test[j]->score = test[j+1]->score; // Отсортировали вектор пузырьком
- test[j+1]->score = temp;
- string templ = test[j]->name;
- test[j]->name = test[j+1]->name;
- test[j+1]->name = templ;
- }
- }
- }
- ofstream hala("test.txt");
- for (int i = 0; i < test.size(); i++) {
- hala << test[i]->score << ":" << test[i]->name << endl; // Записали его в файл. В качестве разделителя использовал :
- }
- hala.close();
- test.clear();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement