Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <vector>
- using namespace std;
- bool cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b){
- return a.second.second < b.second.second;
- }
- int main(){
- int n, m;
- cout << "Please enter the number of rows and columns of the matrix:\n";
- cin >> n >> m;
- int A[n + 1][m + 1], T[m + 1][n + 1];
- cout << "Please enter the matrix:\n";
- for(int i = 1;i <= n;i ++){
- for(int j = 1;j <= n;j ++){
- cin >> A[i][j];
- T[j][i] = A[i][j];
- }
- }
- vector<pair <int, pair <int, int> > > ansA, ansT;
- for(int i = 1;i <= n;i ++){
- for(int j = 1;j <= m;j ++){
- if(A[i][j])
- ansA.push_back (make_pair(i, make_pair(j, A[i][j])));
- if(T[i][j])
- ansT.push_back (make_pair(i, make_pair(j, T[i][j])));
- }
- }
- cout << "The triple list of matrix is:\n";
- for(auto x : ansA){
- cout << x.first << ' ' << x.second.first << ' ' << x.second.second << endl;
- }
- cout << "The triple list of transpose of matrix is:\n";
- for(auto x : ansT){
- cout << x.first << ' ' << x.second.first << ' ' << x.second.second << endl;
- }
- sort(ansA.begin(), ansA.end(), &cmp);
- cout << "The sorted triple list of matrix is:\n";
- for(auto x : ansA){
- cout << x.first << ' ' << x.second.first << ' ' << x.second.second << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement