03 July 2015

UVA 10226 - Hardwood Species (MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
map <string ,double> mp ;

int main()
{
    long long i, t, j;
    double time;
    char c;
    scanf("%lld %c", &t, &c);
    getchar();
    string y, str;
    double sum;
    char data[1000];
    for (i = 1; i <= t; i++)
    {

        time = 0;
        while (gets(data))
        {

            str = data;
            if (x.size() == 0)
                break;
            else
            {

                time = time + 1;
                mp[str] = mp[str] + 1;
            }
        }
        map<string, double>::iterator it;
        for (it = mp.begin(); it != mp.end(); it++)
        {
            cout << it->first <<" ";
            sum = (it->second / time) * 100;
            printf("%.4lf\n", sum);
        }
        if (i != t)
            cout << "\n";
        mp.clear();
    }

    return 0 ;
}

02 July 2015

UVA 12592 - Slogan Learning of Prin.. (STL MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 12592
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

string str1 , str2 , str ;
map<string,string>mp ;

int main()
{

    in slogan ;
    cin>>slogan ;
    getchar() ;
    while(slogan--)
    {
        getline(cin,str1) ;
        getline(cin,str2) ;
        mp[str1] = str2 ;
    }
    in n ;
    cin>>n ;
    getchar() ;
    while(n--)
    {
        getline(cin,str) ;
        cout<<mp[str]<<endl ;
    }
    mp.clear() ;
    return 0 ;
}

UVA 11308 - Bankrupt Baker (MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 11308
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

typedef std::pair <long long, string> IntPair;
vector<pair<long long, string> >v;
int main()
{
    long long i, t, j, k, total, sum, i1;
    cin >> t;
    string x, y, x1, x2;
    int n, m, b, c;
    map<string, long long>store;
    map<long long, string>v1;

    for (i1 = 1; i1 <= t; i1++)
    {
        getchar();
        getline(cin, x1);
        cin >> n >> m >> b;
        for (j = 1; j <= n; j++)
        {
            cin >> x >> c;
            store[x] = c;

        }
        for (k = 1; k <= m; k++)
        {
            getchar();
            getline(cin, x2);
            cin >> total;
            sum = 0;
            for (j = 1; j <= total; j++)
            {
                cin >> x >> c;
                sum = sum + (store[x])*c;
            }
            if (sum <= b)
            {
                v.push_back(make_pair(sum,x2));
            }
        }
        transform(x1.begin(), x1.end(), x1.begin(), ::toupper);
        sort(v.begin(), v.end());
        cout << x1 << "\n";
        if (v.size() > 0)
        {
            for (i = 0; i < v.size(); i++)
            {
                cout << v[i].second << "\n";
            }
        }
        else
        {
            cout << "Too expensive!\n";
        }
        cout << "\n";
        store.clear();
        v.clear();
    }
    return 0 ;
}

UVA 11286 - Conformity (MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 11286
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
int main()
{
    map<string,in>mp ;
    vector<string> data ;
    map<string,in>::iterator it ;
    in n ;
    string str, s ;

    while(cin>>n && n)
    {
        in mx =0 ;
        for(in i=0 ; i<n ; i++)
        {
            str.clear() ;
            for(in j=0 ; j<5 ; j++)
            {
                cin>>s ;
                data.push_back(s) ;
            }

            sort(data.begin(), data.end()) ;

            for(in j=0 ; j<data.size(); j++)
            {
                str+=data[j] ;
            }

            mp[str]++ ;
            if(mx<mp[str])
                mx = mp[str] ;
            data.clear() ;
        }
        in cnt =0 ;
        for(it=mp.begin() ; it!=mp.end() ; it++)
        {
            if(it->second == mx)
                cnt = cnt + mx ;
        }
        pf("%d\n",cnt) ;
        mp.clear() ;
    }
    return 0 ;
}

UVA 10295 - Hay Points (MAP)


/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

map <string, in> mp ;
string str , data ;
in job , descript, salary ;

int main()
{
    while(cin>>job>>descript)
    {
        for(in i=1 ;i <=job ; i++)
        {
            cin>>str>>salary ;
            mp[str] = salary ;
        }
        for(in i=1 ; i<=descript ; i++)
        {
            in k =0 ;
            while(cin>>data)
            {
                in len = data.size() ;
                if(data[0]=='.' && len==1)
                    break ;
                if(mp.find(data)!=mp.end())
                {
                    k = k + mp[data] ;
                }
            }
            pf("%d\n",k) ;
        }


    }
    return 0 ;
}

UVA 10282 - Babelfish (MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict: accepted
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

string a,b,str ,s;
map <string, string> mp ;

int main()
{
    while(1)
    {
        getline(cin,s) ;
       if(s=="")
            break ;
            istringstream cs(s) ;
        cs>>a>>b ;
        mp[b] = a ;
    }

    while(cin>>a)
    {
        if(mp.find(a)!=mp.end())
        {
            cout<<mp[a]<<endl ;
        }
        else
            pf("eh\n") ;
    }
    return 0 ;
}

UVA 10132 - File Fragmentation (MAP)

/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 10132
verdict:
***/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))

string str[100] ;
map<string,in> mp ;
map<string, in> :: iterator it ;

int main()
{
    in test ;
    cin>>test ;
    char ch[500] ;
    getchar() ;
    gets(ch) ;
    while(test--)
    {
        in k=0 ;
        while(gets(ch))
        {
            if(ch[0]==NULL)
                break ;
            str[k++] = ch ;
        }

        in minimum = 10000 , maximum =0 ;
        for(in i=0 ; i<k ; i++)
        {
            if(minimum>str[i].size())
                minimum = str[i].size() ;
            if(maximum<str[i].size())
                maximum = str[i].size() ;
        }
        mp.clear() ;
        in len = maximum + minimum ;
        for(in i=0 ; i<k ; i++)
        {
            for(in j=i+1 ; j<k ; j++)
            {
                string temp = str[i] + str[j] ;
                if(len == temp.size())
                {
                    it = mp.find(temp) ;
                    if(it!=mp.end())
                        mp[temp]++ ;
                    else
                        mp[temp] =1 ;
                }

                temp = str[j] + str[i] ;
                if(len==temp.size())
                {
                    it = mp.find(temp) ;
                    if(it!=mp.end())
                        mp[temp]++ ;
                    else
                        mp[temp] =1 ;
                }
            }
        }

        in t =0 ;
        string ans ;
        for(it = mp.begin() ; it!=mp.end() ; it++)
        {
            if(it->second > t)
            {
                t = it->second ;
                ans = it-> first ;
            }
        }
        cout<<ans<<endl ;
        if(test)
            pf("\n") ;
    }
    return 0 ;
}

UVA 10679 - I Love Strings!!