Uva 11340 Solution

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
map<char, int>p;

ll counts(string s)
{
    int i;
    ll c = 0;
    for(i=0;i<s.size();i++)
    {
        if(p[s[i]] > 0)
        {
            c = c + p[s[i]];
        }
    }
    return c;
}

int main()
{
    int n, m, a, b, c, i;
    cin >> m;

    while(m--)
    {
        cin >> n;
        char ch;

        for(i=1;i<=n;i++)
        {
            cin >> ch >> a;
            p[ch] = a;
        }

        cin >> b;
        getchar();

        string s;
        ll c = 0;
        for(i=1;i<=b;i++)
        {
            getline(cin, s);
            ll t = counts(s);
            c = c + t;
        }

        double d = (double)c/100;

        cout << showpoint;
        cout << fixed;
        cout << setprecision(2);
        cout << d << "$" << endl;

        p.clear();
    }
    return 0;
}

Comments