MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Wednesday, March 6, 2013

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