How to sort 2D arrays in C++ ?

Hi!

I want to ask how can I sort top 10 numbers that appears most.

before sort-http://postimg.org/image/6la0fajl9/
after sort-http://postimg.org/image/e5nyth7bv/

Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<stdlib.h>
using namespace std;
const int broi=101;
const int broi2=6;
int tirash[broi][broi2];
int main()
{
 cout<<"                           Frist Draw"<<endl<<endl;
int i,j;
    for (i=1;i<101;i++){
                for (j=1;j<7;j++){ 
                tirash[i][j]=rand()%49+1;
                
        }
        }
        for (i=1;i<101;i++){
                cout<<"Drawling:"<<i<<": "<<tirash[i][1]<<","<<tirash[i][2]<<","<<tirash[i][3]<<","<<tirash[i][4]<<","<<tirash[i][5]<<","<<tirash[i][6];
                if(i%2) { cout<<"      "; } else { cout<<endl; }
        }
        
        cout<<endl;
        
int a1,a2; 
int sum[1000],b;
for(int i=0;i<1000;i++) sum[i]=0;
for (a1=0;a1<broi;a1++)
{    for (a2=0;a2<broi2;a2++)
{ b=tirash[a1][a2]; sum[b]++;
}
}

for(int j=1;j<1000;j++) if(sum[j]!=0) cout<<j<<" appear "<<sum[j]<<" times"<<endl;

system("PAUSE");
return 0;
}
Last edited on
> How to sort 2D arrays in C++ ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iterator>
#include <algorithm>

int main ()
{
    const int N = 3 ;
    int a[N][4] = { {0,1,2,3}, {4,5,0,1}, {2,3,4,5} };

    for( const auto& row : a )
    {
        for( int v : row ) std::cout << v << ' ' ;
        std::cout << '\n' ;
    }
    std::cout << '\n' ;

    std::sort( std::begin( a[0] ), std::end( a[N-1] ) ) ;

    for( const auto& row : a )
    {
        for( int v : row ) std::cout << v << ' ' ;
        std::cout << '\n' ;
    }
    std::cout << '\n' ;
}

http://coliru.stacked-crooked.com/a/87f6f79c78e89f89
Topic archived. No new replies allowed.