Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #include <vector>
- #include <functional>
- using namespace std;
- ofstream out("output.txt");
- class Sound
- {
- private:
- double pitch;
- double playingTime;
- public:
- Sound(): pitch(0), playingTime(0)
- {
- }
- void Set(double tmp, double temp)
- {
- pitch = tmp;
- playingTime = temp;
- }
- bool comp(Sound &x)
- {
- if(x.pitch == this->pitch)
- return x.playingTime < this->playingTime;
- else return x.pitch > this->pitch;
- }
- void print()
- {
- out << pitch << " " << playingTime << endl;
- }
- };
- int main()
- {
- ifstream in("input.txt");
- vector <Sound> melody;
- Sound x;
- int tmp, temp;
- in >> tmp;
- double n, m;
- for(int i = 0; i < tmp; i++)
- {
- in >> n >> m;
- x.Set(n, m);
- melody.push_back(x);
- }
- in >> temp;
- temp--;
- in.close();
- nth_element(melody.begin(), melody.begin() + temp, melody.end(), mem_fun_ref(&Sound::comp));
- out << "N-element: ";
- melody[temp].print();
- out << "Sounds before N-element:" << endl;
- for(int i = 0; i < temp; i++)
- melody[i].print();
- out <<"Sounds after N-element:" << endl;
- for(int i = ++temp; i < tmp; i++)
- melody[i].print();
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement