MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Friday, September 27, 2013

dinamic initialization of constructor

#include <iostream>

using namespace std;
class student
{
    private:
    int year;
    int amount;
    float total;
    public:
    student(int a,int y,float r=.12);
    student(int a,int y,int d);
    void display();
};
 student::student(int a,int y,float r)
{
    amount=a;
    year=y;
    total=a;
    for(int i=1;i<=year;i++)
    {
        total=total+total*r;
    }
}
 student::student(int a,int y,int d)
{
    amount=a;
    year=y;
    total=a;
    for(int i=1;i<=year;i++)
    {
        total=total+amount*((float)(d)/100);
        amount=total;
    }
}
void student::display()
{
    cout<<"The resultant value is "<<total<<endl;
}
int main()
{
    int a,b,c;
    float f;
    while(cin>>a>>b>>c)
    {
        student ob(a,b,c);
        ob.display();
        cin>>a>>b>>f;
        student ob1(a,b,f);
        ob1.display();
        cin>>a>>b;
        student ob2(a,b);
        ob2.display();
    }
    return 0;
}

using multple constructor of c++ program

#include <iostream>
using namespace std;
class student
{
    private:
    float a;
    float b;
    public:
    student()
    {

    }
    student(float x,float y)
    {
        a=x;
        b=y;
    }
    friend student sum(student,student);
    void display(student);
};
student sum(student c1,student c2)
{
    student c3;
    c3.a=c1.a+c2.a;
    c3.b=c1.b+c2.b;
    return (c3);
}
void student::display(student k)
{
    cout<<"The resultant is="<<k.a<<" + j"<<k.b<<endl;
}
int main()
{
    student ob2[1000],t;
    float x,y,d,z;
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
        cin>>x>>y;
        student ob(x,y);
        cin>>d>>z;
        student ob1(d,z);
        ob2[i]=sum(ob,ob1);
        }
        for(int i=0;i<n;i++)
        {
          t=ob2[i];
          ob2[i].display(t);
        }
    }
    return 0;
}

#include <iostream>
using namespace std;
class student
{
    private:
    float a;
    float b;
    public:
    student()
    {

    }
    student(float x,float y)
    {
        a=x;
        b=y;
    }
    friend student sum(student,student);
    void display(student);
};
student sum(student c1,student c2)
{
    student c3;
    c3.a=c1.a+c2.a;
    c3.b=c1.b+c2.b;
    return (c3);
}
void student::display(student k)
{
    cout<<"The resultant is="<<k.a<<" + j"<<k.b<<endl;
}
int main()
{
    student ob2[1000],t;
    float x,y,d,z;
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
        cin>>x>>y;
        student ob(x,y);
        cin>>d>>z;
        student ob1(d,z);
        ob2[i]=sum(ob,ob1);
        }
        for(int i=0;i<n;i++)
        {
          t=ob2[i];
          ob2[i].display(t);
        }
    }
    return 0;
}

Sunday, May 12, 2013

codeforces contest program

#include <iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
using namespace std;
class name
{
    int p;
    int q,m;
    int r,c;
    public:
    void member(int n);
};
void name::member(int n)
{
    c=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            r=i*i+j*j;
            p=int(sqrt(i*i+j*j));
            q=p*p;
            if(r>n*n)
            break;
            if(r==q)
            {
            c=c+1;
            }
        }
    }
    cout<<c<<endl;
}
int main()
{
    int a;
    name ob;
    while(cin>>a)
    {
        ob.member(a);
    }
    return 0;
}

Thursday, May 2, 2013

sort using class of c++ program

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class node
{
    public:
    string name;
    int age;
    int roll;
    float marks;
};
bool com(const node as,const node k)
{
    if(as.name<k.name)
    return true;
    if((as.name<k.name)||(as.age<k.age))
    return true;
    if(as.marks>k.marks)
    return true;
}
int main()
{
    int n;
    string s;
    int a;
    int r;
    double m;
    node g;
    while(cin>>n)
    {
        vector<node>v;
        for(int i=0;i<n;i++)
        {
        cin>>s;
        cin>>a;
        cin>>r;
        cin>>m;
        g={s,a,r,m};
        v.push_back(g);
        }
    sort(v.begin(),v.end(),com);
    for(int i=0;i<v.size();i++)
    cout<<v[i].name<<" "<<v[i].age<<" "<<v[i].roll<<" "<<v[i].marks<<endl;
    }
    return 0;
}

Thursday, April 25, 2013

c++program using vector

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class name
{
 public:
 char a;
 int b;
};
bool com(const name g,const name t)
{
    if(g.a==t.a)
    if(g.b<t.b)
    return 1;
    else
    return 1;
}
int main()
{
    int n;
    char a;
    int b;
    name ob;
    while(cin>>n)
    {
        vector<name>v;
        for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            ob={a,b};
            v.push_back(ob);
        }
        vector<name>s(v);
        sort(s.begin(),s.end(),com);
        for(int i=0;i<s.size();i++)
        cout<<s[i].a<<" "<<s[i].b<<endl;
    }
    return 0;
}

Tuesday, April 16, 2013

using stack of c/c++ program

#include <iostream>
#include<stack>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    int a;
    int k;
    while(cin>>n)
    {
        stack<int>st;
        for(int i=0;i<n;i++)
        {
            cin>>a;
            st.push(a);
        }
        stack<int>::size_type t;
        t=st.size();
        for(int i=0;i<t;i++)
        {
            k=st.top();
            cout<<k<<" ";
            st.pop();
        }
        cout<<endl;
    }
    cout << "Hello world!" << endl;
    return 0;
}

Saturday, April 6, 2013

preorder tree coding of c program

#include<stdio.h>
#define max 10000
long a[max],n,i,j,large,l,r;
void swap(long j,long large)
{

    int p;
    p=a[j];
    a[j]=a[large];
    a[large]=p;
}
void show(long n)
{
for(i=1;i<=n;i++)
scanf("%ld",&a[i]);
for(j=n/2;j>=1;j--)
{
 function(j);
}
for(j=1;j<=n;j++)
printf("%ld ",a[j]);
printf("\n");
}
void function(long j)
{
    l=2*j;
    r=l+1;
    if(l<=n&&a[j]<a[l])
    large=l;
    else
    large=j;
    if(r<=n&&a[j]<a[r])
    large=r;
    swap(j,large);
    if(j!=large)
    {
    function(large);
    }

}
int main()
{
    while(scanf("%ld",&n)!=EOF)
    {
        show(n);
    }
    return 0;
}

Friday, April 5, 2013

maximum value of given a seires

#include<stdio.h>
#define min -1000000
#define maxi 1000
int a[maxi],ms;
void maximum(int p,int r)
{
 int i,s,max;
 int left,right,t,c;
 int sum=0;
 int k;
 max=min;
 for(i=r;i>=p;i--)
 {
     sum=sum+a[i];
     if(sum>max)
     {
     max=sum;
     left=r-i;
     right=i;
     }
 }
 s=r-p;
 if(s==1)
 {
     left=p;
     right=r;
 }
 else
 {
 right=left+1;
 left=i+1;
 }
 k=max;
 if(k>ms)
 {
   ms=k;
   t=left;
   c=right;
   left=t;
   right=c;
 }
}
int function(int p,int r)
{
    int q;
    q=(p+r)/2;
    maximum(p,q);
    maximum(q+1,r);
    maximum(p,r);
   printf("The maximum value is %d\nThe lower boundery is %d \nThe upper boundery is %d\n",ms,p,r);
}
int main()
{
 int n;
 int i;
 while(scanf("%d",&n)!=EOF)
 {
     for(i=1;i<=n;i++)
     scanf("%d",&a[i]);
     ms=0;
     function(1,n);
 }
 return 0;
}

Wednesday, April 3, 2013

uva solve problem 11858

#include<stdio.h>
#define max 10000000000
long s,L[1000002],R[1000002],a[1000002];

void merge(long p,long q,long r)
{
    long n1,n2;
    long i,j,k;
    n1=q-p+1;
    n2=r-q;
    for(i=1;i<=n1;i++)
    L[i]=a[p+i-1];
    for(j=1;j<=n2;j++)
    R[j]=a[q+j];
    i=1;
    j=1;
    L[n1+1]=max;
    R[n2+1]=max;
    for(k=p;k<=r;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i];
            i++;
        }
        else
        {
            a[k]=R[j];
            s+=n1-i+1;
            j++;
        }
    }

}

void ms(long p,long  r)
{
    long  q;
    if(p<r)
    {
        q=(p+r)/2;
        ms(p,q);
        ms(q+1,r);
        merge(p,q,r);
    }
}
int main()
{
long n;
long i;
while(scanf("%d",&n)!=EOF)
{
    for(i=1;i<=n;i++)
    scanf("%ld",&a[i]);
    i=1;
    s=0;
    ms(i,n);
    printf("%ld\n",s);

}
return 0;
}

uva solve problem 10810

#include<stdio.h>
#define max 10000000000
long s,L[500002],R[500002],a[500002];

void merge(long p,long q,long r)
{
    long n1,n2;
    long i,j,k;
    n1=q-p+1;
    n2=r-q;
    for(i=1;i<=n1;i++)
    L[i]=a[p+i-1];
    for(j=1;j<=n2;j++)
    R[j]=a[q+j];
    i=1;
    j=1;
    L[n1+1]=max;
    R[n2+1]=max;
    for(k=p;k<=r;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i];
            i++;
        }
        else
        {
            a[k]=R[j];
            s+=n1-i+1;
            j++;
        }
    }

}

void ms(long p,long  r)
{
    long  q;
    if(p<r)
    {
        q=(p+r)/2;
        ms(p,q);
        ms(q+1,r);
        merge(p,q,r);
    }
}
int main()
{
long n;
long i;
while(scanf("%d",&n)!=EOF)
{
    if(n==0)
    break;
    for(i=1;i<=n;i++)
    scanf("%ld",&a[i]);
    i=1;
    s=0;
    ms(i,n);
    printf("%ld\n",s);

}
return 0;
}

Tuesday, April 2, 2013

merge sort of c program

#include<stdio.h>
long long int s;
void ms(int a[],int p,int r)
{
    int q;
    if(p<r)
    {
        q=(p+r)/2;
        ms(a,p,q);
        ms(a,q+1,r);
        merge(a,p,q,r);
    }
}
void merge(int a[],int p,int q,int r)
{
    int n1,n2;
    int i,j,k;
    int L[1000],R[1000];
    n1=q-p+1;
    n2=r-q;
    for(i=1;i<=n1;i++)
    L[i]=a[p+i-1];
    for(j=1;j<=n2;j++)
    R[j]=a[q+j];
    i=1;
    j=1;
    L[n1+1]=12542568;
    R[n2+1]=3655423654;
    for(k=p;k<=r;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i];

            i++;
        }
        else
        {
            a[k]=R[j];
            s+=n1+1-i;
            j++;
        }
    }
}
int main()
{
int n;
int i,a[100];
while(scanf("%d",&n)!=EOF)
{
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    i=1;
    s=0;
    ms(a,i,n);
    printf("%d\n",s);
}
return 0;
}

merge sort of c++

#include <iostream>
#define max 1000
using namespace std;
class name
{
 private:
 int q;
 public:
void merge(int b[],int p,int r);
};
void name::merge(int b[],int p,int r)
{
    if(p<r)
    {
    q=(p+r)/2;
    merge(b,p,q);
    merge(b,q+1,r);
    msort(b,p,q,r);
    }
}

}
void msort(int b[],int p,int q,int r)
{
    int n1,n2,s,v,j;
    int L[max];
    int R[max];
    n1=p-q+1;
    n2=r-q;
    for(int i=1;i<=n1;i++)
    L[i]=b[i+p-1];
    for(int j=1;j<=n2;j++)
    R[j]=b[q+j];
    s=1;
    v=1;
    for(int k=p;k<=r;k++)
    {
        if(L[s]<=R[v])
        {
         b[k]=L[s];
         s=s+1;
        }
        else
        {
            b[k]=R[v];
            v=v+1;
        }

    }
}
int main()
{
    name ob;
    int n,t,i;
    int b[max];
    t=1;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        {
        cin>>b[i];
        }
        ob.merge(b,t,n);
        for(i=1;i<=n;i++)
        cout<<b[i];


    }
    return 0;
}

merge sort of c++

#include <iostream>
#define max 1000
using namespace std;
class name
{
 private:
 int q;
 public:
void merge(int b[],int p,int r);
};
void name::merge(int b[],int p,int r)
{
    if(p<r)
    {
    q=(p+r)/2;
    merge(b,p,q);
    merge(b,q+1,r);
    msort(b,p,q,r);
    }
}

}
void msort(int b[],int p,int q,int r)
{
    int n1,n2,s,v,j;
    int L[max];
    int R[max];
    n1=p-q+1;
    n2=r-q;
    for(int i=1;i<=n1;i++)
    L[i]=b[i+p-1];
    for(int j=1;j<=n2;j++)
    R[j]=b[q+j];
    s=1;
    v=1;
    for(int k=p;k<=r;k++)
    {
        if(L[s]<=R[v])
        {
         b[k]=L[s];
         s=s+1;
        }
        else
        {
            b[k]=R[v];
            v=v+1;
        }

    }
}
int main()
{
    name ob;
    int n,t,i;
    int b[max];
    t=1;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        {
        cin>>b[i];
        }
        ob.merge(b,t,n);
        for(i=1;i<=n;i++)
        cout<<b[i];


    }
    return 0;
}

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;
}