Skip to content

Instantly share code, notes, and snippets.

@heriniaina
Last active April 12, 2017 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heriniaina/8398642879581ff9db99ffc41125d985 to your computer and use it in GitHub Desktop.
Save heriniaina/8398642879581ff9db99ffc41125d985 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
string source[12][3] = {
{"Jaona", "Math", "3"},
{"Marka", "Math", "5"},
{"Solofo", "Math", "8"},
{"Jaona", "fizika", "4"},
{"Marka", "fizika", "3"},
{"Solofo", "fizika", "10"},
{"Jaona", "siansa", "5"},
{"Solofo", "siansa", "6"},
{"Marka", "histo", "5"},
{"Solofo", "histo", "6"},
{"Marka", "malagasy", "2"},
{"Solofo", "malagasy", "9"}
};
/*
* alaina ny colonnes misy
*/
map<string, int> cols;
map<string, int> rows;
for (int i = 0; i < 12; i++){
if(cols.find(source[i][1]) == cols.end())
{
cols[ source[i][1] ] = 1;
}
if(rows.find(source[i][0]) == rows.end())
{
rows[ source[i][0] ] = 1;
}
}
/*
cout << "Column size: " << cols.size() << endl;
cout << "Row size: " << rows.size() << endl;
*/
//associative maps
map< string, map < string, string> > res;
for (int i = 0; i < 12; i++){
res[ source[i][0]][ source[i][1]] = source[i][2];
}
//affichage
for(map<string, int>::iterator col = cols.begin(); col != cols.end(); ++col)
{
cout << "\t" << col->first;
}
cout << endl;
for(map<string, int>::iterator row = rows.begin(); row != rows.end(); ++row)
{
cout << row->first;
for (map<string, int>::iterator col = cols.begin(); col != cols.end(); ++col){
if(res[row->first][col->first] == "")
{
cout << "\t" << "0";
}
else
{
cout << "\t" << res[row->first][col->first];
}
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment