Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct info {
- string nom;
- int valor;
- };
- bool comp1(const info& a, const info& b) {
- if (a.nom != b.nom) return a.nom < b.nom;
- return a.valor < b.valor;
- }
- bool comp2(const info& a, const info& b) {
- if (a.valor != b.valor) return a.valor < b.valor;
- return a.nom < b.nom;
- }
- int main() {
- int n;
- cin >> n;
- while (n > 0) {
- --n;
- int m;
- cin >> m;
- vector<info> v(2*m);
- for (int i = 0; i < 2*m; i += 2) {
- string s, t;
- int valor;
- cin >> s >> t >> valor;
- v[i].nom = s;
- v[i].valor = -valor;
- v[i + 1].nom = t;
- v[i + 1].valor = valor;
- }
- sort(v.begin(), v.end(), comp1);
- vector<info> res(m);
- for (int i = 0; i < m; ++i) {
- res[i].nom = v[2*i].nom;
- res[i].valor = v[2*i].valor + v[2*i + 1].valor;
- }
- sort(res.begin(), res.end(), comp2);
- for (int i = 0; i < m; ++i) {
- cout << res[i].nom << " " << res[i].valor << endl;
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment