简体   繁体   English

根据出现次数按升序对数组进行排序

[英]Sort array based on count of occurrences in ascending order

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java. java - 如何根据该值在java中按升序出现的次数排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

Try: 尝试:

    int a[] = {0,0,0,1,3,3,2,1,3,5,6,0};
    Arrays.sort(a);
    System.out.println(Arrays.toString(a));

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

Answer in python:在python中回答:

 n=input()
 arr=[int(i) for i in n.split(' ')]
 dict={}
 for i in arr:
     if(i in dict.keys()):
         dict[i]+=1
     else:
         dict[i]=1
 ans=[]
 while len(ans)<=len(arr) and dict!={}:
        maxval=min(list(dict.values()))
        keys=[]
        for key in dict.keys():
              if(dict[key]==maxval):
                   keys+=[key]
        keys=sorted(keys)
        for i in keys:
            ans+=[i]*dict[i]
            del dict[i] 
 print(ans)    

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

How can I arrange the elements in an array based on the number of occurrences of that value in ascending order in java.如何在Java中根据该值的出现次数以升序排列数组中的元素。

This is what I've tried:这是我尝试过的:

int a[]={0,0,0,1,3,3,2,1,3,5,6,0};
int b=a.length;
for(int i=0;i<b;i++) {
    for(int j=0;j<i;j++) {
        int temp;
        if( a[j]>a[i]) {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}

for(int r=0;r<a.length;r++) {
    System.out.println(a[r]);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM