Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
1.0 kB
2
Indexable
Never
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

struct Mass
{
    long long m;
    string ind;
    long double ms;
};
map <char,long double> mapa;

void recalc(Mass & mass)
        {
            mass.ms = mass.m;
            for (auto e:mass.ind)
            {
                mass.ms = mass.ms * mapa[e];
            }
        };

void init()
{
    mapa['g'] = 1;
    mapa['p'] = 16380;
    mapa['t'] = 1000000;
    mapa['m'] = 1e-3;
    mapa['k'] = 1e3;
    mapa['M'] = 1e6;
    mapa['G'] = 1e9;
}

bool compare(const Mass & mass1,const Mass & mass2)
{
    return mass1.ms < mass2.ms;
}

int main(){
    init();
    int n;
    cin>>n;
    vector <Mass> a(n);
    for (int i = 0; i < n; i++){
        cin>>a[i].m;
        cin>>a[i].ind;
        recalc(a[i]);


    }
    sort(a.begin(), a.end(), compare);
    for(auto e:a)
    {
        cout<<e.m<<" "<<e.ind<<endl;
    }
    return 0;
}