Saturday, 21 October 2017

UVA 417 - Word Index c++ implementation


Problem Type: map (Java TreeMap)
Problem Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=358&mosmsg=Submission+received+with+ID+20216008

Source code :

 /***
    Tarequzzaman Khan
    CSE'12
    2012331514
    */
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int>mp;
void load()
{
    queue<string> q;
    string s = "";
    int cou =1;
    for(int i=97; i<=122; i++)
    {
        char c = i;
        s+=c;
        mp[s]=cou;
        q.push(s);
        cou ++;
        s="";
    }
    while(!q.empty())
    {
        string s = q.front();
        q.pop();
        for(int i=97; i<=122; i++)
        {
            char c = i;
            int len = s.length();
            if(s[len-1]<c)
            {
                string m = s+c;
                if(m.length()>5)
                    break;
                mp[m]=cou;
                q.push(m);
                cou ++;
            }
        }
    }
}
int main()
{
 /***
    Tarequzzaman Khan
    CSE'12
    2012331514
    */
    load();
    string s ;
    while(cin >>s)
    {
     cout << mp[s] << endl;
    }
}

Friday, 20 October 2017

11988 - Broken Keyboard (a.k.a. Beiju Text) c++ implementation

Problem Type: C++ STL list (Java LinkedList)


Implementation:

#include<bits/stdc++.h>
using namespace std;
 /***
    Tarequzzaman Khan
    CSE'12
    2012331514
    */
int main()
{
    string s;
    while(cin >>s)
    {

        int tag =0;
        string sub="",output="";
        for(int i=0; i<s.length(); i++)
        {
            if(s[i]=='[')
            {
                tag =1;
                if(sub.compare("")!=0)
                {
                    output=sub + output;
                    sub ="";
                }
            }
            else if(s[i]==']')
            {
                tag = 0;
                if(sub.compare("")!=0)
                {
                    output=sub + output;
                    sub ="";
                }
            }
            else if(tag==1)
            {
                sub += s[i];
            }
            else
            {
                output += s[i];
            }
        }
        if(sub.compare("")!=0)
        {
         output = sub + output;
        }
        cout << output << endl;
    }
}

Monday, 16 October 2017

11362 - Phone List(C++ implementation)

Problem Type: Trie Data Structure


#include<bits/stdc++.h>
using namespace std;

struct Node
{
    map<char, Node*> a;
    int flag;

    Node()
    {
        flag = 0;
    }
};

Node* root;
void insert_text(Node *x, string s)
{
    for(int i = 0; i < s.size(); i++)
    {
        if(x->a.count(s[i]) == 0)
        {
            x->a[ s[i] ] = new Node;
        }
        x = x->a[ s[i] ];
    }
    x->flag++;
}

int search_text(Node* x, string s)
{
    int len = s.length();
    int i=0;
    int flag_count =0;
    while (i<len)
    {
        char c = s[i];
        if(x->a.count(s[i]) != 0)
        {
            x = x->a[s[i]];
            if(x->flag==1)
            {
                flag_count++;
            }
            else if(x->flag>1)
            {
                return 0;
            }
        }
     
        i++;
    }
    if(flag_count>1)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

int main()
{
    int test;
    scanf("%d",&test);
    for(int i=0; i<test; i++)
    {
        int how_number,k=0;
        string str[10003];
        root = new Node;
        scanf("%d",&how_number);
        int j;
        for(j=0; j<how_number; j++)
        {
            string number;
            cin >> number;
            insert_text(root,number);
            str[j]=number;

        }
        int mm=0;
        for(int k=0; k<j; k++)
        {
            int p = search_text(root,str[k]);
            if(p==0)
            {
                mm=1;
                break;
            }

        }
        if(mm==0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }

}

ট্রিগার এর মাধ্যমে ডাটা ইনসার্ট - insert data using Database Trigger (Mysql)

সর্বপ্রথম আমরা প্রবলেমটা বুঝিঃ আমি একটা টেবিলের একটা কলামের ভ্যালুর উপর ডিপেন্ড করে আরেকটা কলামে ডাটা insert করব । এই কাজটা ট্রি...