MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Saturday, March 30, 2013

recersive function

#include <iostream>
using namespace std;
class name
{
  private:
  int p;
  public:
  int sum(int n);
};
int name::sum(int n)
{
    if(n==0)
    return 0;
    else
    return (sum(n-1)+n);
}
int main()
{
    name ob;
    int a;
    while(cin>>a)
    {
    cout<<ob.sum(a)<<endl;
    }
    return 0;
}

Friday, March 29, 2013

code jamer contest problem

#include<iostream>
#include<cstring>
#define max 1000
using namespace std;
int main()
{
    char a[max],b[max];
    int c,la,n,t;
        cin.get(a,max);
        la=strlen(a);
        c=0;
        t=0;
        for(int j=la-1;j>=0;j--)
        {
            if(a[j]==' ')
            {
                for(int k=j+1;k<la-t;k++)
                b[c++]=a[k];
                b[c++]=' ';
                t=c;
            }

        }
        for(int s=0;s<la;s++)
            {
                if(a[s]==' ')
                break;
                else
                b[c++]=a[s];
            }
        cout<<"Case #"<<": "<<b<<endl;
    return 0;
}

new item of c++ code

#include <iostream>
using namespace std;
class name
{
    private:
    char a[100];
    public:
    void member(char b[])
    {
    cout<<b;
    }
};
int main()
{
    name ob;
    char a[100]="computerscience&engineering";
    ob.member(&a[8]);
    return 0;
}

Thursday, March 28, 2013

www.use of friend class

#include <iostream>
#include<cstring>
#define max 1000
using namespace std;
class name1
{
    private:
    char a[max];
    char b[max];
    int la,lc;
    public:
    void member()
    {
        cin.get(a,max);
        la=strlen(a);
        lc=la;
        for(int i=0;i<la;i++)
        b[i]=a[i];
    }
    friend class name2;
};
class name2
{
    private:
    char c[max];
    int lb;
    public:
    void member1(name1&la)
    {
        lb=la.lc;
        for(int j=0;j<lb;j++)
        {
        c[j]=la.b[j];
        cout<<c[j];
        }
        cout<<"\n";
    }
    friend class name3;

};
class name3
{
    private:
    char string[max];
    int ld;
    public:
    void member2(name2&lk)
    {
    ld=lk.lb;
    for(int k=ld-1;k>=0;k--)
    {
    string[k]=lk.c[k];
    cout<<string[k];
    }
    cout<<endl;
    }
};

int main()
{
    name1 ob;
    name2 ot;
    name3 om;
    ob.member();
    ot.member1(ob);
    om.member2(ot);
    return 0;
}

Wednesday, March 27, 2013

discribtion of friend class

#include <iostream>
#include<cstring>
#define max 1000
using namespace std;
class name1
{
    private:
    char a[max],c[max];
    int la,d;
    public:
    void member()
    {
        cin.get(a,max);
        la=strlen(a);
        d=la;
        for(int j=0;j<d;j++)
        c[j]=a[j];
    }
 friend class name2;
};
class name2
{
    private:
    char b[max];
    int c;
    public:
    void member1(name1&la)
    {
    c=la.d;
    for(int i=0;i<c;i++)
    {
    b[i]=la.c[i];
    cout<<b[i];
    }
    }
};
int main()
{
    name1 ob;
    name2 ot;
    ob.member();
    ot.member1(ob);
    return 0;
}

useing friend class

#include <iostream>
using namespace std;
class name1
{
    private:
    int a;
    public:
    void function()
    {
        a=0;
    }
    void get(int x)
    {
    a=x;
    }
    void output()
    {
    cout<<a<<endl;
    }
    friend class name2;

};
class name2
{
    private:
    int b;
    public:
    void function1()
    {
    b=0;
    }
    void get1(name1&x)
    {
    b=x.a+25;
    }
    void output1()
    {
    cout<<b<<endl;
    }
};
int main()
{
    int c;
    name1 ob;
    name2 ot;
    while(cin>>c)
    {
        ob.get(c);
        ot.get1(ob);
        ob.output();
        ot.output1();
    }
    return 0;
}

Saturday, March 23, 2013

using char of insertion short

#include <iostream>
#define max 1000
using namespace std;
class name
{
    private:
    int n,tm,p;
    char a[max];
    char b[max];
    public:
    void member(int k);
    void output();
};
void name::member(int k)
{
        n=k;
        for(int i=0;i<n;i++)
        cin>>a[i];
        b[0]=a[0];
        for(int j=1;j<n;j++)
        {
          tm=a[j]-48;
           p=j-1;
          while((tm<(b[p]-48))&&(p>=0))
          {
            b[p+1]=b[p];
            p=p-1;
           }
           b[p+1]=tm+48;
        }

}
void name::output()
{
    for(int i=0;i<n;i++)
    cout<<b[i]<<" ";
    cout<<endl;
}
int main()
{
    int m;
    name ob;
    while(cin>>m)
    {
    ob.member(m);
    ob.output();
    }
    return 0;
}

insertion short

#include <iostream>
#define max 1000
using namespace std;
class name
{
    private:
    int n,tm,p;
    int a[max];
    int b[max];
    public:
    void member(int k);
    void output();
};
void name::member(int k)
{
        n=k;
        for(int i=0;i<n;i++)
        cin>>a[i];
        b[0]=a[0];
        for(int j=1;j<n;j++)
        {
          tm=a[j];
           p=j-1;
          while((tm<b[p])&&(p>=0))
          {
            b[p+1]=b[p];
            p=p-1;
           }
           b[p+1]=tm;
        }

}
void name::output()
{
    for(int i=0;i<n;i++)
    cout<<b[i]<<" ";
    cout<<endl;
}
int main()
{
    int m;
    name ob;
    while(cin>>m)
    {
    ob.member(m);
    ob.output();
    }
    return 0;
}

Tuesday, March 19, 2013

diferent type of c++ code

#include <iostream>
#include<cstring>
#include<cstdio>
#define max 1000
using namespace std;
class name
{
    private:
    int la,c;
    char a[max];
    public:
    void member();
    void output();
};
void name::member()
{
    cin.get(a,max);
    la=strlen(a);
}
void name::output()
{
    if((a[0]>=65)&&(a[0]<96))
    cout<<a[0];
    else
    cout<<(char)(a[0]-32);
    for(int i=1;i<la;i++)
    {
        c=0;
        if(a[i]==' ')
        {
        if(((a[i+1]=='a')||(a[i+1]=='A'))&&((a[i+3]=='d')||(a[i+3]=='D'))&&((a[i+2]=='n')||(a[i+2]=='N')))
        c++;
        else
        {
        if((a[i+1]>=65)&&(a[i+1]<96))
        cout<<a[i+1];
        else
        cout<<(char)(a[i+1]-32);
        }
        }
    }
}
int main()
{
     name ob;
    ob.member();
    ob.output();
    return 0;
}

Saturday, March 16, 2013

c++

#include<iostream>
using namespace std;
class name
{
    private:
    int n;
    double t;
    public:
    void member(int p);
};
void name::member(int p)
 {
        n=p;
        for(int i=0;i<n;i=i+2)
        {
        for(int j=0;j<=i;j++)
        cout<<(char)(65+j);
        cout<<endl;

        }

};
int main()
{
    int k;
    name sob;
    while(cin>>k)
    {
    sob.member(k);
    }
    return 0;
}

using c++ coide how we can cout char to take int ?

#include<iostream>
using namespace std;
class name
{
    private:
    int n;
    double t;
    public:
    void member(int p);
};
void name::member(int p)
 {
        n=p;
        for(int i=0;i<n;i=i+2)
        {
        for(int j=0;j<=i;j++)
        cout<<(char)(65+j);
        cout<<endl;

        }

};
int main()
{
    int k;
    name sob;
    while(cin>>k)
    {
    sob.member(k);
    }
    return 0;
}

Thursday, March 14, 2013

code of c++ problem

#include <iostream>
using namespace std;
class name
{
    private:
    int n;
    public:
    void member(int p)
    {
        for(int i=0;i<p;i=i+2)
        {
            for(int j=i;j<p;j=j+2)
            cout<<" ";
            for(int k=0;k<=i;k++)
            cout<<"0";
            cout<<endl;

        }
    }
};
void tmem(int p)
{
    name ob;
    ob.member(p);
}
int main()
{
    int n;
    name ob;
    while(cin>>n)
    {
    tmem(n);
    }
    return 0;
}

Wednesday, March 13, 2013

uva solve problem 10773 - Back to Intermediate Math

#include<stdio.h>
#include<math.h>
int main()
{
     int n,i;
     double u,v,d;
      double t1,t2,t,a;
      scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf",&d,&v,&u);
            if((v>=u)||(v<=0)||(u<=0)||(d<=0))
            printf("Case %d: can't determine\n",i);
            else
            {
            a=sqrt(u*u-v*v);
            t1=d/a;
            t2=d/u;
            t=t1-t2;
            printf("Case %d: %.3lf\n",i,t);
            }
        }
    return 0;
}

uva solve problem 11723 - Numbering Roads

#include<stdio.h>
int main()
{
    long int n,r,k;
    int i;
    for(i=1;i<=10002;i++)
    {
        scanf("%ld%ld",&r,&n);
        if((r==0)&&(n==0))
        break;
        k=(r-1)/n;
        if(k>26)
        printf("Case %d: impossible\n",i);
        else
        printf("Case %d: %ld\n",i,k);

    }
    return 0;
}

uva solve problem 834 - Continued Fractions

#include<stdio.h>
int main()
{
    long long int n,a,b,c,x,y;
    while(scanf("%lld%lld",&a,&b)==2)
    {
        n=a/b;
        printf("[%lld;",n);
        c=a%b;
        while(c!=0)
        {
            x=b;
            y=c;
            n=x/y;
            printf("%lld",n);
            c=x%y;
            if(c>0)
            printf(",");
            b=y;

        }
        printf("]\n");
    }
    return 0;
}

uva solve problem 713 - Adding Reversed Numb

#include<stdio.h>
#include<string.h>
int main()
{
    char a[1000],b[1000],c[1000];
    int l,la,lb,i,j,k,h,s,p,q,n,m,u;
    while(scanf("%d",&n)==1)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%s%s",a,b);
            la=strlen(a);
            lb=strlen(b);
            l=la;
            if(lb>l)
            l=lb;
            h=0;
            m=0;
            for(j=0;j<l;j++)
            {
                if(la>j)
                p=a[j]-48;
                else
                p=0;
                if(lb>j)
                q=b[j]-48;
                else
                q=0;
                s=p+q+h;
                c[m]=s%10+48;
                h=s/10;
                m++;
            }
            if(h>0)
            {
                c[m]=h+48;
                m++;
            }
            for(k=0;k<m;k++)
            {
                if(c[0]==48)
                for(u=1;u<m;u++)
                {
                    if(c[u]>48)
                    printf("%c",c[u]);
                    k++;
                }
              else
              printf("%c",c[k]);
            }
         printf("\n");
        }
    }
    return 0;
}

uva solve problem 591 - Box of Bricks

#include<stdio.h>
int main()
{
    int n;
    int i,j,k,l,m,count,total,ave;
    int a[109];
    m=0;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        break;
        total=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            total=total+a[i];
        }
        ave=total/n;
        count=0;
        for(j=0;j<n;j++)
        {
        if(a[j]>ave)
        count=count+(a[j]-ave);
        }
        printf("Set #%d\n",++m);
        printf("The minimum number of moves is %d.\n",count);

    }
    return 0;
}

uva solve problem 580 - Critical Mass

  #include <stdio.h>
    int dp[100][4];
    int dangerCount(int size,int stacked)
    {
        if(size==0)
        return dp[size][stacked]=(stacked==3);
        else if(dp[size][stacked]!=-1)
        return dp[size][stacked];
        else
        return dp[size][stacked] = dangerCount(size-1,(stacked>=3)?stacked:0)+dangerCount(size-1,(stacked<3)?stacked+1:stacked);
    }
    int main()
    {
        int i,j;
        for(i=0;i<100;i++)
            for(j=0;j<4;j++)
                dp[i][j]=-1;
        scanf("%d",&i);
        while(i)
        {
          // dangerCount(i,0);
            printf("%d\n",dangerCount(i,0));
            scanf("%d",&i);
        }
        return 0;
    }

uva solve problem 580 - Critical Mass

  #include <stdio.h>
    int dp[100][4];
    int dangerCount(int size,int stacked)
    {
        if(size==0)
        return dp[size][stacked]=(stacked==3);
        else if(dp[size][stacked]!=-1)
        return dp[size][stacked];
        else
        return dp[size][stacked] = dangerCount(size-1,(stacked>=3)?stacked:0)+dangerCount(size-1,(stacked<3)?stacked+1:stacked);
    }
    int main()
    {
        int i,j;
        for(i=0;i<100;i++)
            for(j=0;j<4;j++)
                dp[i][j]=-1;
        scanf("%d",&i);
        while(i)
        {
          // dangerCount(i,0);
            printf("%d\n",dangerCount(i,0));
            scanf("%d",&i);
        }
        return 0;
    }

uva solve problem 406 prime cuts

#include<stdio.h>
#include<math.h>
int main()
{
    long int a[1010],i,j,n,c,k,b[1010],p,l,s,m,z;
    while(scanf("%ld %ld",&n,&c)!=EOF)
    {
        for(i=0;i<=n;i++)
        a[i]=0;
        z=(long)(sqrt(n));
        for(i=2;i<=z;i++)
        {
            if(a[i]==0)
            for(j=2;i*j<=n;j++)
            a[i*j]=1;
        }
        k=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]==0)
            {
            b[k]=i;
            k++;
            }
        }
       printf("%ld %ld:",n,c);
       if(c>=k)
       {
       for(i=0;i<k;i++)
       printf(" %ld",b[i]);
       }
       else
       {
           if((k%2)==0)
           {
               c=c*2;
               p=((k/2)+1)-(c/2)-1;
               m=(k/2)+(c/2);
               if(p<=0)
               {
                   for(i=0;i<k;i++)
                   printf(" %ld",b[i]);
               }
               else
               {
               for(i=p;i<m;i++)
               printf(" %ld",b[i]);
               }
           }
           else
           {
               c=c*2-1;
               p=(long)((ceil)(k/2)-(floor)(c/2));
               m=(ceil)(k/2)+(floor)(c/2);
               if(p<=0)
               {
                   for(i=0;i<k;i++)
                   printf(" %ld",b[i]);
               }
               else
               {
               for(i=p;i<=m;i++)
               printf(" %ld",b[i]);
               }
           }
       }
       printf("\n\n");
    }
    return 0;
}

uva solve problem 406 prime cuts

#include<stdio.h>
#include<math.h>
int main()
{
    long int a[1010],i,j,n,c,k,b[1010],p,l,s,m,z;
    while(scanf("%ld %ld",&n,&c)!=EOF)
    {
        for(i=0;i<=n;i++)
        a[i]=0;
        z=(long)(sqrt(n));
        for(i=2;i<=z;i++)
        {
            if(a[i]==0)
            for(j=2;i*j<=n;j++)
            a[i*j]=1;
        }
        k=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]==0)
            {
            b[k]=i;
            k++;
            }
        }
       printf("%ld %ld:",n,c);
       if(c>=k)
       {
       for(i=0;i<k;i++)
       printf(" %ld",b[i]);
       }
       else
       {
           if((k%2)==0)
           {
               c=c*2;
               p=((k/2)+1)-(c/2)-1;
               m=(k/2)+(c/2);
               if(p<=0)
               {
                   for(i=0;i<k;i++)
                   printf(" %ld",b[i]);
               }
               else
               {
               for(i=p;i<m;i++)
               printf(" %ld",b[i]);
               }
           }
           else
           {
               c=c*2-1;
               p=(long)((ceil)(k/2)-(floor)(c/2));
               m=(ceil)(k/2)+(floor)(c/2);
               if(p<=0)
               {
                   for(i=0;i<k;i++)
                   printf(" %ld",b[i]);
               }
               else
               {
               for(i=p;i<=m;i++)
               printf(" %ld",b[i]);
               }
           }
       }
       printf("\n\n");
    }
    return 0;
}

uva solve problem 424 - Integer Inquiry

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,l,la,lb,m,h,p,r,d;
    char a[1000],b[1000],c[1000],s[1000];
    lb=1;
    c[0]=48;
       for(i=1;i<=100;i++)
        {
            d=0;
            scanf("%s",a);
            if(a[d]==48)
            break;
            la=strlen(a);
            j=0;
            for(i=la-1;i>=0;i--)
            {
                b[j++]=a[i];

            }
            h=0;
            l=la;
            if(l<lb)
            l=lb;
            for(k=0;k<l;k++)
            {
                if(la>k)
                b[k]=b[k]-48;
                else
                b[k]=0;
                if(lb>k)
                c[k]=c[k]-48;
                else
                c[k]=0;
                p=b[k]+c[k]+h;
                s[k]=p%10+48;
                h=p/10;

            }
            s[k]=48;
            if(h>0)
            s[k++]=h+48;
            for(r=0;r<k;r++)
            c[r]=s[r];
            l=r;
            lb=l;
        }
        for(m=r-1;m>=0;m--)
        printf("%c",c[m]);
        printf("\n");
    return 0;
}

uva solve problem 100 - The 3n + 1 problem

#include<stdio.h>
int main()
{
    long long int i,j,k,l,m,n,p,a,t;
    while(scanf("%lld%lld",&i,&j)==2)
    {
        if((i==0)&&(j==0))
        break;
        m=0;
        p=i;
        t=j;
        if(i>j)
        {
        k=p;
        p=t;
        t=k;
        }
        for(n=p;n<=t;n++)
        {
            l=n;
            a=1;
            while(l!=1)
            {
                if((l%2)==0)
                {
                l=l/2;
                a++;
                }
                else
                {
                l=3*l+1;
                a++;
                }

            }
            if(a>m)
            m=a;
        }
        printf("%lld %lld %lld\n",i,j,m);
    }
    return 0;
}

using vector solve problem

#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;

int main()
{
   char b;
   while((b=cin.get())!=EOF)
   {
    vector<char>a;
    a.push_back(b);
    for(int i=0;i<a.size();i--)
    cout<<a[i];
   }
    return 0;
}

Sunday, March 10, 2013

ELECTRIC FIELD

DEFINATION OF ELECTRIC FIELD:
An electric field surrounds electrically charged particles and time varying magnetic fields.This electric field exerts a force on their electrically charged objects.
আসলে আমরা electric field বলতে বুজি যে একটি বিদ্যুখতত্রকে বেষ্টিত করে কণা এবং সময় পরিবতনের মাধম্যে চোম্বক ক্ষেত্রে অভিযুক্ত করা হয়।এই বিদ্যুখত্র একটি শক্তি অভিযুক্ত জিনেসের উপর প্রয়গ করা হয়।এটি হলো electric field।

Saturday, March 9, 2013

static variable

এখন আমরা আলচনা করব static variable সম্পকে। আসলে মানুষ বিপদে না পড়লে শিখতে পারে না । যেমনঃ আমি তার বাস্তব প্রমান।আমি নিজেও প্রথমে static variable নাম শুনলে খিব্রে উটতাম এবং ভাবতাম ইহা অনেক কঠিন।কারন উহা সম্পকে আমার বিন্দুমাএ ধারনা ছিলনা এমনকি বুজতাম না তেমন ভাল।তাই আমি চাই আমার মতো কষ্ট না করে আর সবাই যাতে ভাল করে বুজতে পারে তাদের জন্য আমার সাইটটি। এখণ কাজ়েড় কখায় যাই।প্রখমে আমরা একটি প্রগ্রাম দেখিঃ

#include <iostream>
using namespace std;
class sample
{
    static int a,b,t;
    public:
    void set(int x,int y)
    {
        a=x;
        b=y;
    }
    ~sample()
    {
    t++;
    }
    void print()
    {
        cout<<a<<"  "<<b<<" "<<t<<endl;
    }
};
int sample::t=0;
int sample::a;
int sample::b;
int main()
{
    int a,b;
    sample s1,s2;
    while(cin>>a>>b)
    {
    s1.set(a,b);
    s1.print();
    s2.print();
    }
    return 0;
}
প্রখমে আমাদেরকে class declare করতে হবে।দেখা যাচ্ছে্ যে আমরা class হিসাবে আমরা sample ব্যবহার করেছি।
static variable হিসাবে a,b,t।আর এখানে  public function হিসাবে void set(int x,int y) এটি ব্যবহার করা হয়েছে।আমরা একটি চিহু সম্পকে অনেকেই জানে না একে scopresulation operator(::)বলা হয়।static variable এর খেত্রে অবশ্যই int sample::কখাটূকূ ঊল্লেখ করতে হবে তানা হলে compiler error দেখাবে।

big integer multiplication

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,l,la,lb,r,h,x,y,s,t,n,z,w;
    char a[140120],b[140120],c[140120],d[140120],v[140120];
    while(scanf("%s%s",c,d)==2)
    {
        la=strlen(c);
        lb=strlen(d);
        l=la+lb;
        j=0;
        for(i=la-1;i>=0;i--)
        {
            a[j]=c[i];
            j++;
        }
        k=0;
        for(t=lb-1;t>=0;t--)
        {
            b[k]=d[t];
            k++;
        }
        for(n=0;n<l;n++)
        v[n]=48;
        v[n]='\0';
        r=-1;
        for(x=0;x<lb;x++)
        {
            h=0;
            for(y=0;y<la;y++)
            {
                s=(a[y]-48)*(b[x]-48)+(v[x+y]-48)+h;
                v[x+y]=s%10+48;
                h=s/10;
                if((x+y)>r)
                r=x+y;
            }
        while(h!=0)
        {
            s=h+(v[x+y]-48);
            v[x+y]=s%10+48;
            h=s/10;
            if(x+y>r)
            r=x+y;
            y++;
        }
        }
        for(z=r;z>0;z--)
        {
            if(v[z]==48)
            r--;
            if(v[z]>48)
            break;
        }
        for(w=r;w>=0;w--)
        printf("%c",v[w]);
        printf("\n");

    }
    return 0;
}

big integer subtruction

#include<stdio.h>
#include<string.h>
int main()
{
    char a[10000],b[100],c[10000],d[10000],result[10000];
    int i,j,k,la,lb,m,l,n,s,v,u,y,x,h,z,p,q,t,e,as;
    while(scanf("%s%s",a,b)==2)
    {
        la=strlen(a);
        lb=strlen(b);
        if(la>lb)
        {
        i=0;
        for(j=la-1;j>=0;j--)
        {
            c[i]=a[j];
            i++;
        }
        l=i;
        k=0;
        for(m=lb-1;m>=0;m--)
        {
            d[k]=b[m];
            k++;
        }
        }
        else if(lb>la)
        {
        i=0;
        printf("-");
        for(j=lb-1;j>=0;j--)
        {
            c[i]=b[j];
            i++;
        }
        l=i;
        k=0;
        for(m=la-1;m>=0;m--)
        {
            d[k]=a[m];
            k++;
        }
        }
        else if(la==lb)
        {
        s=strcmp(a,b);
        if(s==0)
        l=s;
        else if(s>0)
        {
        i=0;
        for(j=la-1;j>=0;j--)
        {
        c[i]=a[j];
        i++;
        }
        l=i;
        k=0;
        for(m=lb-1;m>=0;m--)
        {
        d[k]=b[m];
        k++;
        }
        }
        else if(s<0)
        {
        i=0;
        printf("-");
        for(j=lb-1;j>=0;j--)
        {
        c[i]=b[j];
        i++;
        }
        l=i;
        k=0;
        for(m=la-1;m>=0;m--)
        {
        d[k]=a[m];
        k++;
        }
        }
        }
        if(la>lb)
        e=lb;
        else
        e=la;
        if(l==0)
        printf("0\n");
        else
        {
            as=0;
            for(u=0;u<l;u++)
            {
                if(l>u)
                p=c[u]-48;
                else
                p=0;
                if(e>u)
                q=d[u]-48;
                else
                q=0;
                h=p-(q+as);
                if(h<0)
                {
                as=1;
                result[u]=10+h+48;
                }
                else
                {
                    result[u]=h+48;
                    as=0;
                }
            }
            for(y=u-1;y>=0;y--)
            {
            if(result[y]!=48)
            break;
            }
            for(t=y;t>=0;t--)
            printf("%c",result[t]);
            printf("\n");
        }
    }
    return 0;
}

big integer division

#include<stdio.h>
#include<string.h>
char a[100000007],b[100000007];
int main()
{
    long int i,j,k,l,la,n,p,t,u;
    while(scanf("%s%ld",a,&n)==2)
    {
        la=strlen(a);
        k=0;
        l=0;
        for(i=0;i<la;i++)
        {
            p=l*10+(a[i]-48);
            b[k]=(p/n)+48;
            l=p%n;
            k++;
        }
        printf("%ld\n",l);
        j=0;
            for(t=0;t<k;t++)
            {
                if(b[t]>48)
                break;
                if(b[t]==48)
                j++;
            }
        for(u=j;u<k;u++)
        printf("%c",b[u]);
        printf("\n");
    }
    return 0;
}

using constructor of c++ program

#include<iostream>
#include<cstdio>
using namespace std;
class sample
{
    private:
    int rollno;
    float marks;
    char name;
    public:
    sample(char c)
    {
     name=c;
    }
    void veriation()
    {
     cout<<name;
    }
};
int main()
{
    int i;
    char m[100],g;
    i=0;
    while((g=cin.get())!=EOF)
    {
    sample smp(g);
    smp.veriation();
    }
    return 0;
}

Thursday, March 7, 2013

uva solve problem 10323 Factorial! You Must be Kidding!!!

#include <iostream>
using namespace std;
int main()
{
    long long int n,i,r;
    while(cin>>n)
    {
        if(n<0&&n%2==0)
        cout<<"Underflow!"<<endl;
        else if(n<0&&n%2!=0)
        cout<<"Overflow!"<<endl;
        else if(n<8)
        cout<<"Underflow!"<<endl;
        else if(n>13)
        cout<<"Overflow!"<<endl;
        else
        {
        r=1;
        for(i=1;i<=n;i++)
        {
         r=i*r;
        }
        cout<<r<<endl;
        }
    }
    return 0;
}

STRUCT

গত দিন আমরা আলোচনা করেছি structure of struct। আজ আমরা দেখব কি ভাবে ইহা কাজ করে।প্রথমে আমরা একটি ছোট প্রগ্রাম দেখিঃ
#include <iostream>
using namespace std;
struct date
{
    int day;
    int month;
    int year;
    int total;
};
void display(struct date one)
{
 cout<<one.day<<endl;
 cout<<one.month<<endl;
 cout<<one.year<<endl;
}
int main()
{
    date today;
    void display(struct date one);
    int a,b,c;
    while(cin>>a>>b>>c)
    {
     today.day=a;
     today.month=b;
     today.year=c;
     display(today);
    }

    return 0;
}

একটা প্রগ্রাম  compile করার সময় এটি কাজ করবে কি না তা নিভর করে তার লাইব্রী ফানশন এর উপর।কারন একটা প্রগ্রাম তখনি compile করা যাবে যখন তার লাইব্রী ফানশন উল্লেখ থাকবে তানা হলে কি ভাবে বুজবে যে প্রগ্রামটা c or c++।যেহতু আমরা c++সম্পকে আলোচনা করব,তাই হেডার ফাইল উল্লেখ করেছি <iostream>।এটি বলতে বুজায় যে এখানে input এবং output stream খাকবে।আমরা দেখতে পাচ্ছি যে using namespace std;নামে কিছূ কখা আসলে এটি তেমন কোন কিছূই না। কারন এটি আসলে কমপাইলারের সমস্যা।কারন কোন কোন কম্পাইলার এটি ছারাই রান করতে পারে আবার কোন কোন কম্পাইলার এটি ছাড়া রান করতে পারে না।তাই আমি মনে করি যে এটি স্মপুন ব্যবহারকারীর উপর নিরভর করবে। কারন তিনি কোন কম্পাইলার ব্যবহার করবে তার উপর নিরভর করবে।
পরে আমরা দেখতে পাচ্ছি struct date নামে কিছূ কখা এখানে date একটি নাম।এটি যেকোন হতে পারে।তারপর একটি ব্রাক্টে । পরে কিছূ variable ।আমি এই সম্পকে কিছূ বলবো না।কারন ইহা সম্পকে সি প্রগ্রামে বিস্তারিত আলোচনা করা হয়েছে।

Wednesday, March 6, 2013

uva solve problem 11743

#include<stdio.h>
int main()
{
    char a[100];
    int i,j,k,m,s,sum,result,t,n,c[100],d,x;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            s=0;
            d=0;
            getchar();
            for(j=0;j<19;j++)
            {
            scanf("%c",&a[j]);
            }
            t=0;
            for(k=0;k<19;k=k+2)
            {
                if(a[k]==' ')
                k++;
                c[t]=(a[k]-48)*2;
                t++;
            }
            for(x=0;x<t;x++)
            {
                while(c[x]!=0)
                {
                    s=s+(c[x]%10);
                    c[x]=c[x]/10;
                }
            }
            for(m=1;m<19;m=m+2)
            {
                if(a[m-1]==' ')
                m=m+1;
                d=d+(a[m]-48);
            }
            sum=s+d;
            result=sum%10;
            if(result==0)
            printf("Valid\n");
            else
            printf("Invalid\n");
        }
    }
    return 0;
}

uva solve problem 10812

#include<stdio.h>
int main()
{
    long int n,a,b,result,r,k,i;
    while(scanf("%ld",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%ld%ld",&a,&b);
            if((a<b)||((a%2==1)&&(b%2==0))||((b%2==1)&&(a%2==0)))
            printf("impossible\n");
            else
            {
            k=(a-b)/2;
            result=b+k;
            printf("%ld %ld\n",result,k);
            }
        }
    }
    return 0;
}

uva solve problem 10473

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    char a[1000];
    long long int sum,i,j,h,k,la,t;
    while(scanf("%s",a)!=EOF)
    {
    la=strlen(a);
    t=a[0]-48;
    if(t<0)
    break;
    if(t==0)
    {
        k=2;
        sum=0;
        for(i=la-3;i>=0;i--)
        {
            sum=sum+(a[k]-48)*pow(16,i);
            k++;
        }
       printf("%lld\n",sum);
    }
    else
    {
    sum=0;
    h=0;
     for(j=la-1;j>=0;j--)
     {
     sum=sum+(a[j]-48)*pow(10,h);
     h=h+1;
     }
   printf("0x");
    printf("%x\n",sum);
    }
    }
return 0;
}

uva solve problem 11984

#include<stdio.h>
int main()
{
    int i,c,d,n;
    double f;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        break;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&c,&d);
            f=1.8*(double)c+32;
            f=f+d;
            f=f-32;
            f=f*5;
            f=f/9;
            printf("Case %d: %.2lf\n",i,f);
        }
    }
    return 0;
}

Tuesday, March 5, 2013

আমরা এখন আলচনা করব struct and class সমপকে ।প্রথমে আমরা structure দেখব যে তারা কিভাবে কাজ করে।
structure of struct:
struct name
{
variable name or data member;
member of function;
 } ;
নিচে আমরা একখানা উদাহারন দেখি তাহলে ভাল বুজা যাবে যেমনঃ
#include <iostream>
using namespace std;
struct DATE
{
    int day ;
    int month;
    int year,total;
    int function(int day,int month,int year)
    {
        total=day+month*30+year*360;
        return total;
    }

};
int main()
{
    int day,month,year;
    struct DATE value;
    cin>>day>>month>>year;
    cout<<value.function (day,month,year);
    return 0;
}

আমরা দেখতে পাইতেচি যে struct এর পরে DATE।আসলে যারা প্রথম তাদের মনে প্রশণ হতে পারে যে এখানে DATE
না দিয়ে অনো কিছূ দেয়া যাবে না।আসলে তেমনটি নয় আপনার ইচ্ছা মত এটি use করতে পারেন। কারন এটি নাম মাএ ,আর নাম যেকোন হইতে পারে। রহিম,করিম,মালেক,খালেক ইতাদি।
পরে আমরা দেখতেছি যে int নামক একটি ENGLISH WORD ।আসলে তা নয় কারন int একটি data type যেটি byte জায়গা দখল করে।আর day,month and year এগুলো variable name
পরে আমরা function() নামে একটি word দেখতে পাচ্ছি।আসলে এটি একটি member function()।

uva problem 10323


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include<string.h>
#include<stdio.h>
using namespace std;

#define DEBUG
#define REP(i,a) for(i=0;i<a;i++)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define VE vector<int>
#define SZ size()
#define PB push_back
char *fac[1005]={0};
void factorial()
{
    fac[0]="1";
fac[1]="1";
int l1=strlen(fac[0]);
int l2=strlen(fac[1]);
int l;
for(long i=2;i<=1002;i++)
{
char str[10000];
l=strlen(fac[i-1]);
long q,T,ca;
    T=0;ca=0;
    for(q=l-1;q>=0;q--)
    {

     int ans=0;
       ans=(fac[i-1][q]-48)*i+ca;
       str[T]=ans%10+48;
       ca=ans/10;
       T++;
    }
    while(ca>0)
    {
      str[T]=ca%10+48;
       ca=ca/10;
      T++;
    }


  str[T]='\0';
  fac[i]=new char[T+1];
   long y=0;
     for(long x=T-1;x>=0;x--,y++)
           fac[i][y]=str[x];
        fac[i][y]='\0';

}
}
int main()
{

int n;
factorial();
while(scanf("%d",&n)!=EOF)
{
  printf("%d!\n",n);
  printf("%s\n",fac[n]);
 // printf("%d\n",strlen(fac[n]));
}
return 0;
}

uva solve problem 10311

#incluide<stdio.h>
#include<math.h>
int N = 100000002;
bool status[100000002];
long prime[8000000];
int search(long value,int left,int right)
{
    int mid;
    if(right<left)
    return right;
    mid=floor((left+right)/2);
         if(prime[mid]==value)
         return mid;
         if(prime[mid]>value)
          search(value,left,mid-1);
        else
          search(value,mid+1,right);

}

int main()
{
    long i, j, sqrtN,k=0;
    status[0]=1;status[1]=1;
    for( i = 2; i <= N; i++ )
    status[i] = 0;
    prime[0]=2;
            k++;
    sqrtN = long( sqrt((double)N) ); // have to check primes up to (sqrt(N))
    for( i = 3; i <= sqrtN; i += 2 )
    {
        if( status[i] == 0 )
        {
            prime[k]=i;
            k++;
            for( j = i * i; j <= N; j += i + i )
            status[j] = 1; // status of the multiple is 1
        }
    }
    for(;i<100000000;i+=2)
    if( status[i] == 0 )
    {
        prime[k]=i;
        k++;
    }

    // printf("%ld\n",k);
   long n,p,q,m,l=k-1,a,b;

   while(scanf("%ld",&n)!=EOF)
   {
    k=0;
    if(n%2==1)
    {
        m=n-2;
        if(status[m]==0&&m>1)
        {
            b=m;a=2;
            k=1;
        }
    }
    else
    {
    p=search(n/2,0,l);
    if(p>=0)
    {
      while(prime[p]<n)
      {
           m=n-prime[p];

        if((status[m]==0&&m%2!=0)||m==2)
        {
            if(m!=prime[p])
            {
                k=1;
                b=prime[p];a=m;
                break;
            }
        }
        p=p+1;
      }
    }
   }
      if(k==0)
      printf("%ld is not the sum of two primes!\n",n);
      else
      {
          if(a>b)
          swap(a,b);
          printf("%ld is the sum of %ld and %ld.\n",n,a,b);
      }

   }

    return 0;
}

uva problem 10300

#include<stdio.h>
int main()
{
    long int i,j,k,n,a,b,c,s,m;
    while(scanf("%ld",&n)==1)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%ld",&m);
            s=0;
            for(j=1;j<=m;j++)
            {
                scanf("%ld%ld%ld",&a,&b,&c);
                s=s+a*c;
            }
            printf("%ld\n",s);
        }
    }
    return 0;
}

uva solve problem 10035

#include<stdio.h>
int main()
{
    long long int i,j,k,l,a,b,la,lb,c[100],d[100],s[100],r,h,z;
    int count;
    for(i=1;;i++)
    {
        scanf("%lld%lld",&a,&b);
        if((a==0)&&(b==0))
        break;
        for(j=0;a!=0;j++)
        {
            c[j]=a%10;
            a=a/10;
        }
        la=j;
        for(k=0;b!=0;k++)
        {
            d[k]=b%10;
            b=b/10;
        }
        lb=k;
        l=la;
        if(l<lb)
        l=lb;
        count=0;
        h=0;
        for(r=0;r<l;r++)
        {
            if(la>r)
            c[r]=c[r];
            else
            c[r]=0;
            if(lb>r)
            d[r]=d[r];
            else
            d[r]=0;
            z=c[r]+d[r]+h;
            s[r]=z%10;
            h=z/10;
            if(h>0)
            count=count+1;
        }
        if(count==1)
        printf("%d carry operation.\n",count);
        else
        {
        if(count>1)
        printf("%d carry operations.\n",count);
        else
        printf("No carry operation.\n");
        }
    }
    return 0;
}

uva solve problem 1006

#include<stdio.h>
int main()
{
    int n,i,c;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        break;
        c=0;
        for(i=2;i<n;i++)
        {
            if(n%i==0)
            c=c+1;
            if(c>0)
            break;
        }
        if(c>0)
        printf("The number %d is a Carmichael number.\n",n);
        else
        printf("%d is normal.\n",n);
    }
    return 0;
}

Monday, March 4, 2013

uva solve problem 272 tex quotex

#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
 {

    int c;
    char ch;
    c=1;
    while((ch=cin.get())!=EOF)
    {
         if(ch=='"')
          {
          c=c+1;
          if(c%2==0)
          cout<<"``";
          else
          cout<<"''";
          }
          else
          cout<<ch;
    }
    return 0;
}

Sunday, March 3, 2013

uva solve problem 11743 - Credit Check

#include<stdio.h>
int main()
{
    char a[100];
    int i,j,k,m,s,sum,result,t,n,c[100],d,x;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            s=0;
            d=0;
            getchar();
            for(j=0;j<19;j++)
            {
            scanf("%c",&a[j]);
            }
            t=0;
            for(k=0;k<19;k=k+2)
            {
                if(a[k]==' ')
                k++;
                c[t]=(a[k]-48)*2;
                t++;
            }
            for(x=0;x<t;x++)
            {
                while(c[x]!=0)
                {
                    s=s+(c[x]%10);
                    c[x]=c[x]/10;
                }
            }
            for(m=1;m<19;m=m+2)
            {
                if(a[m-1]==' ')
                m=m+1;
                d=d+(a[m]-48);
            }
            sum=s+d;
            result=sum%10;
            if(result==0)
            printf("Valid\n");
            else
            printf("Invalid\n");
        }
    }
    return 0;
}

uva solve problem 11716 - Digital Fortress Acc

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int p,n,i,j,k,l,s,u,t;
    double r;
    char a[10010],b[102][102];
    while(scanf("%d",&n)!=EOF)
    {
          getchar();
        for(i=1;i<=n;i++)
        {

            gets(a);
            l=strlen(a);
            r=sqrt(l);
            p=r;
            if((r-p)!=0)
            printf("INVALID\n");
            else
            {
                s=0;
                for(j=0;j<p;j++)
                {
                    for(k=0;k<p;k++)
                    {
                        b[j][k]=a[s++];
                    }
                }
                for(u=0;u<p;u++)
                {
                    for(t=0;t<p;t++)
                    printf("%c",b[t][u]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}