Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- int c1(int x){
- while(x >= 10)
- x/=10;
- return x;
- }
- int t(int x){
- int c=0;
- while(x != 0){
- if(x % 2 == 1)
- c++;
- x/=2;
- }
- return c;
- }
- using namespace std;
- int main(){
- struct {
- int x,c,nr;
- }
- V[100],aux;
- ifstream f1("atestat.in");
- ofstream f2("atestat.out");
- int n,i,j;
- f1>>n;
- for(i=1;i <= n;i++){
- f1>>V[i].x;
- V[i].c=c1(V[i].x);
- V[i].nr=t(V[i].x);
- }
- for(i=1;i<n;i++)
- for(j=i+1;j<=n;j++)
- if(V[i].c < V[j].c){
- aux=V[i];
- V[i]=V[j];
- V[j]=aux;
- }
- for(i=1;i <= n; i++)
- f2<<V[i].x<<" ";
- f2<<endl;
- for(i=1;i<n;i++)
- for(j=i+1;j<=n;j++)
- if(V[i].nr > V[j].nr){
- aux=V[i];
- V[i]=V[j];
- V[j]=aux;
- }
- else
- if(V[i].nr == V[j].nr)
- if(V[i].x < V[j].x){
- aux=V[i];
- V[i]=V[j];
- V[j]=aux;
- }
- for(i=1;i<=n;i++)
- f2<<V[i].x<<" ";
- f1.close();
- f2.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement