Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 10:29

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



HELP 2d arrays sort by sum of numbers in a row

Discussion on HELP 2d arrays sort by sum of numbers in a row within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
HELP 2d arrays sort by sum of numbers in a row

Hi, i'd like to ask for some help about a problem i got... So i got this code right now:
Code:
Code:
        const int rows = 5;
        const int cols = 3;
        int tocke = 0;
       
        int tekmovalci[rows][cols]={{7, 6, 9},
                                    {8, 7, 8},
                                    {6, 9, 10},
                                    {7, 7, 9},
                                    {8, 8, 10}};
                                       
        for(int r=0; r<rows; r++){
                cout << r+1 << ". ";
                for(int c=0; c<cols; c++){
                        cout << tekmovalci[r][c] << " ";
                        tocke += tekmovalci[r][c];       
                }
                cout << tocke << endl;
                tocke = 0;       
        }
and the 'int tocke' represents the sum of all numbers in a row, and now i'd like to sort the output by the value of sum.

this is the current output:
1. 7 6 9 22
2. 8 7 8 23
3. 6 9 10 25
4. 7 7 9 23
5. 8 8 10 26

and i want it like this:
5. 8 8 10 26
3. 6 9 10 25
2. 8 7 8 23
4. 7 7 9 23
1. 7 6 9 22

so can anyone post me a solution of this ??
Hikarim is offline  
Old 12/02/2012, 15:45   #2
 
kissein's Avatar
 
elite*gold: 0
Join Date: Sep 2005
Posts: 427
Received Thanks: 87
You can use an stack container. That would be last item in first item out.
see also
kissein is offline  
Reply


Similar Threads Similar Threads
C++ Mehrdimensionale Arrays
08/14/2011 - C/C++ - 7 Replies
Hey Leute, Ich lern C++ schon seit 2 Monaten und bin jetzt bei den Arrays und Strukturen (Vll. brauchte ich ein bissl. lange,aber dafür behersche ich das gelernte zu 100%). und zwar habe ich da ein BspQuelltext: #include <iostream> using namespace std; // Hauptprogramm
vereinfachen mit arrays
02/03/2011 - AutoIt - 2 Replies
ich versuche grad das hier zu vereinfachen: $Fach1=IniRead("C:\info.ini","Fach ","1","") $Fach2=IniRead("C:\info.ini","Fach ","2","") $Fach3=IniRead("C:\info.ini","Fach ","3","") $Fach4=IniRead("C:\info.ini","Fach ","4","") $Fach5=IniRead("C:\info.ini","Fach ","5","") $Fach6=IniRead("C:\info.ini","Fach ","6","") $Fach7=IniRead("C:\info.ini","Fach ","7","") $Fach8=IniRead("C:\info.ini","Fach ","8","")
Arrays! Hilfe!
06/29/2010 - AutoIt - 13 Replies
Hallo e*pvp, Es ist mir jetzt peinlich aber irgendwann musste ich es fragen! Also Ich habe ein Problem undzwar versteh ich nicht was Arrays sind. Ich versteh den Sinn nicht und nicht wie man sie Anwenden kann! Die ganzen Texte aus Wikipedia und Arrays Tutorials helfen mit nicht! Bitte hilft mir was genau Arrays sind und wie man sie sinnvoll anwenden kann! Ich hoffe einer kann mir helfen :( !
charname numbers or guild numbers will take block?
02/21/2010 - Silkroad Online - 6 Replies
charname numbers or guild numbers will take block? some friends said that to me is it right?



All times are GMT +1. The time now is 10:29.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.