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 10679 - I Love Strings!!