UVA 11340 Newspaper Solution

UVA 11340 Newspaper Solution


#include<iostream>
#include<string.h>
#include<map>
#include<stdio.h>


using namespace std;
map<char,int> mymap;
map<char,int>::iterator mit;

int main()
{
    freopen("input.txt","r",stdin);
    int i,k,m,test,value;
    char ch;
    double sum;
    char str[10010];
    cin>>test;
    while(test--)
    {
        cin>>k;
        mymap.clear();
        while(k--)
        {
            cin>>ch>>value;
            mymap[ch]=value;

        }
        cin>>m;
        getchar();
        sum=0.00;
        while(m--)
        {
            gets(str);
            k=strlen(str);
            for(i=0;i<k;i++)
            {
                ch=str[i];
                mit=mymap.find(ch);
                if(mit!=mymap.end())
                    sum=sum+mit->second;
            }
        }
        printf("%.2lf$\n",sum/100);
    }
    return 0;
}

Comments

  1. plz someone xplain if(mit!=mymap.end())

    ReplyDelete
  2. map mymap is used to store key pair value where key is char and value is int.
    map::iterator mit, mit is a iterator for map.
    mit=mymap.find(ch); returns the key & pair as a object. It returns a pointer if key is found otherwise it returns end's address of map (it means key is not present in map)

    ReplyDelete

Post a Comment

Popular posts from this blog

uva 679 - Dropping Balls Solution

uva 481 - What Goes Up Solution

uva-10077 Solution --- The Stern-Brocot Number System