Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //problema #1608
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <utility>
- using namespace std;
- ifstream f("sortare_divizori.in");
- ofstream g("sortare_divizori.out");
- short nrdiv(int a)
- {
- int d=1, rez=0;
- for (d=1; d*d<a; ++d)
- if (a%d==0)
- rez+=2;
- if (d*d==a)
- ++rez;
- return rez;
- }
- bool comp(pair<int, int>A, pair<int,int>B)
- {
- if (A.second<B.second)
- return true;
- else if (A.second==B.second && A.first>B.first)
- return true;
- return false;
- }
- vector<pair<int,int>>v;
- int main()
- {
- short n; int x;
- f>>n;
- v.resize(n+1);
- int i;
- for (i=1; i<=n; ++i)
- {
- f>>x;
- v[i]=make_pair(x, nrdiv(x));
- }
- sort (v.begin(), v.end(), comp);
- for (i=n; i>=1; --i)
- g<<v[i].first<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement