uva 10895 Matrix Transpose Solution
Matrix Transpose Solution
uva id : erfan05Accepted Time : 0.000
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
typedef vector<int> vector_int;
typedef map<int, vector_int> map_int_vector_int;
int main(){
freopen("input.txt", "r", stdin);
map_int_vector_int index_map,value_map;
vector_int index, value;
int i, j, m, n, val, pos, x;
while (cin >> m >> n){
index_map.clear();
value_map.clear();
for (i = 1; i <= n; i++){
vector_int v1,v2;
index_map[i] = v1;
value_map[i] = v2;
}
for (i = 1; i <= m; i++){
cin >> x;
if (x == 0)
continue;
index.clear();
for (j = 1; j <= x; j++){
cin >> pos;
index_map[pos].push_back(i);
index.push_back(pos);
}
for (j = 0; j < x; j++){
cin >> val;
value_map[index[j]].push_back(val);
}
}
cout << n << " " << m << endl;
for (i = 1; i <= n; i++){
x = index_map[i].size();
cout << x;
if (x == 0){
cout << endl << endl;
}
else{
for (j = 0; j < x; j++){
cout << " " << index_map[i][j];
}
cout << endl;
for (j = 0; j < x - 1; j++){
cout << value_map[i][j] << " ";
}
cout << value_map[i][j] << endl;
}
}
}
return 0;
}
Comments
Post a Comment