02 July 2015

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!!