Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <vector>
- struct Record {
- int id;
- std::string latitude;
- std::string longitude;
- };
- std::ostream& operator<<(std::ostream& os, const Record& record) {
- os << record.id << ' ' << record.latitude << ' ' << record.longitude;
- return os;
- }
- std::istream& operator>>(std::istream& is, Record& record) {
- is >> record.id >> record.latitude >> record.longitude;
- return is;
- }
- int main() {
- const std::string inputFile = "input.txt";
- const std::string outputFile = "output.txt";
- std::vector<Record> records;
- std::cout << "Reading records from '" << inputFile << "' to memory"
- << std::endl;
- {
- std::ifstream ifs(inputFile);
- Record record;
- while (ifs >> record) {
- records.push_back(std::move(record));
- }
- }
- std::cout << "Sorting records in memory" << std::endl;
- std::sort(records.begin(), records.end(),
- [](const Record &r1, const Record &r2) {
- return r1.longitude > r2.longitude;
- });
- std::cout << "Writing records to '" << outputFile << "' file" << std::endl;
- {
- std::ofstream ofs(outputFile);
- for (const auto &record : records) {
- ofs << record << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement