Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- class liczba
- {
- private:
- int first;
- int second;
- int diff;
- public:
- liczba(int _first, int _second)
- {
- first = _first;
- second = _second;
- diff = first - second;
- }
- int getDiff()
- {
- return diff;
- }
- int getFirst()
- {
- return first;
- }
- int getSecond()
- {
- return second;
- }
- };
- int main()
- {
- int n;
- vector<liczba> results;
- cin >> n;
- results.reserve(n/2);
- int * tb = new int[n];
- for(int i = 0; i < n; i ++)
- {
- cin >> tb[i];
- }
- for(int i = 0; i < n; i ++)
- {
- for(int j = 0; j < n; j ++)
- {
- if(tb[i] > tb[j])
- {
- if(results.empty())
- {
- liczba l (tb[i],tb[j]);
- results.push_back(l);
- }
- if(results.at(0).getDiff() > (tb[i] - tb[j]))
- {
- results.clear();
- liczba l (tb[i],tb[j]);
- results.push_back(l);
- }
- else if(results.at(0).getDiff() == (tb[i] - tb[j]) && (results.at(0).getFirst() != tb[i]) && (results.at(0).getSecond() != tb[j]) )
- {
- liczba l (tb[i],tb[j]);
- results.push_back(l);
- }
- }
- }
- }
- if(results.size() > 0)
- {
- cout << results.at(0).getDiff() << endl;
- }
- for(unsigned int i = 0; i < results.size(); i ++)
- {
- cout << results.at(i).getFirst() << " " << results.at(i).getSecond() <<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement