Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream f("sortare_divizori.in");
- ofstream of("sortare_divizori.out");
- int divizori(int x)
- {
- int cnt = 0;
- for(int j = 1; j * j <= x; j++)
- {
- if(x % j == 0) cnt++;
- }
- return cnt;
- }
- bool comparator(int a, int b)
- {
- if(divizori(a) > divizori(b)) return true;
- return false;
- }
- int main()
- {
- int n, v[1000], i;
- f >> n;
- for(i = 1; i <= n; i++)
- f >> v[i];
- sort(v, v + n, comparator);
- for(i = 1; i <= n; i++)
- of << v[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement