Wednesday, January 22, 2014

UVa 1124 - Celebrity Jeopardy solution

Problem link :  UVa 1124 - Celebrity Jeopardy

Solution : 


#include<stdio.h>
int main()
{
    char a[100];
    while(gets(a))
    {
        puts(a);
    }
    return 0;
}




UVa 913 - Joana and the Odd Numbers solution

Problem link :  UVa 913 - Joana and the Odd Numbers

Solution : 


#include<stdio.h>
int main()
{
    long long int a,n;
    while(scanf("%lld",&n)==1)
    {
        a=(((n*(n+2)/2)*3)-6);
        printf("%lld\n",a);
    }
    return 0;
}




UVa 694 - The Collatz Sequence solution

Problem link :  UVa 694 - The Collatz Sequence

Solution : 


#include<stdio.h>
int main()
{
    long long int a,l,c,i,m=0,n;
    while(scanf("%lld %lld",&a,&l)==2)
    {
        if(a<0 && l<0)
            break;
        c=0; i=a; m++;
        while(a<=l)
        {
            c++;
            if(a==1)
                break;
            if(a%2==0)
                a=a/2;
            else
                a=3*a+1;
        }
        printf("Case %lld: A = %lld, limit = %lld, number of terms = %lld\n",m,i,l,c);
    }
    return 0;
}


UVa 686 - Goldbach's Conjecture (II) solution

Problem link :  UVa 686 - Goldbach's Conjecture (II)

Solution : 


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

bool Isp(int n)
{
    int i,j;
    if(n==1)
    return 0;

    if(n==2)
    return 1;

    if(n%2==0)
    return 0;

    int l=sqrt(n);

    for(i=3;i<=l;i+=2)
    {
        if(n%i==0)
        return 0;
    }
    return 1;
}
int main()
{
    int a,b,i,m,n,c;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        break;

        a=0,b=0,c=0;

        for(i=n-1;i>=n/2;i--)
        {
            if(Isp(i))
            {
                m=n-i;
                if(Isp(m))
                {
                    c++;
                }
            }
        }

        printf("%d\n",c);
    }
    return 0;
}



UVa 591 - Box of Bricks solution

Problem link :  UVa 591 - Box of Bricks

Solution : 


#include<stdio.h>
int main()
{
    int a[105],n,sum,avg,k,i,st=1;
    while(scanf("%d",&n)==1)
    {
        if(n==0) break;
        sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        avg=sum/n; k=0;
        for(i=1;i<=n;i++)
        {
            if(a[i]>avg) k+=(a[i]-avg);
        }
        printf("Set #%d\n",st); st++;
        printf("The minimum number of moves is %d.\n\n",k);
    }
    return 0;
}




UVa 579 - Clock Hands solution

Problem link :  UVa 579 - Clock Hands

Solution : 


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    double h,m,t,i,j,k,l,n,a;
    while(scanf("%lf:%lf", &h, &m)==2)
    {
        if(h==0 && m==0)
            break;

        i=((h*30)+(m/2));
        j=(m*6);

        t=i-j;

        if(t<0)
            t*=-1;

        if(t>180)
            t=360-t;

        printf("%.3lf\n",t);
    }
    return 0;
}


UVa 543 - Goldbach's Conjecture solution

Problem link :  UVa 543 - Goldbach's Conjecture

Solution : 


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

bool Isp(int n)
{
    int i,j;
    if(n==1)
    return 0;

    if(n==2)
    return 1;

    if(n%2==0)
    return 0;

    int l=sqrt(n);

    for(i=3;i<=l;i+=2)
    {
        if(n%i==0)
        return 0;
    }
    return 1;
}
int main()
{
    int a,b,i,m,n;
    while(scanf("%d",&n)==1)
    {
        if(n==0)
        break;

        else if(n<6 && n>0)
            {
                printf("Goldbach's conjecture is wrong.\n");
                continue;
            }

        a=0,b=0;

        for(i=n-1;i>=n/2;i--)
        {
            if(Isp(i))
            {
                m=n-i;
                if(Isp(m))
                {
                    if(i%2==1 && m%2==1)
                    {
                        a=i;
                        b=m;
                        break;
                    }
                }
            }
        }

         if(a>0 && b>0 && a<=b)
            printf("%d = %d + %d\n",n,a,b);
        else if(a>0 && b>0 && b<a)
            printf("%d = %d + %d\n",n,b,a);
        else
            printf("Goldbach's conjecture is wrong.\n");
    }
    return 0;
}


UVa 494 - Kindergarten Counting Game solution

Problem link :  UVa 494 - Kindergarten Counting Game

Solution :


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

int main()
{
    char a[10005];
    int i,l,cnt;
    while(gets(a))
    {
        l=strlen(a); cnt=0;
        for(i=0;i<l;i++)
        {
            if(isalpha(a[i]) && !isalpha(a[i+1])) cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}
 




UVa 488 - Triangle Wave solution

Problem link :  UVa 488 - Triangle Wave

Solution :


#include<stdio.h>
int main()
{
    long long int amp, fre, a,i,j,t,m,tc;

    scanf("%lld", &tc);

    for(t=1;t<=tc;t++)
    {
    scanf("%lld %lld", &amp, &fre);

    for(a=1;a<=fre;a++)
    {
        for(i=1; i<=amp; i++)
        {
          for(j=1; j<=i; j++)
            {
                printf("%lld", i);
            }
            printf("\n");
        }
        for(i=amp-1; i>=1; i--)
        {
            for(j=1; j<=i; j++)
            {
                printf("%lld", i);
            }
            if(t==tc&&a==fre&&i==1)
                break;
            printf("\n");
        }
        printf("\n");
    }
    }
    return 0;
}

UVa 483 - Word Scramble solution

Problem link :  UVa 483 - Word Scramble

Source code : 


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
    char a[100005],b[100005],c[100005];
    int i,j,k,l,m,n;
    while(gets(a))
    {
        l=strlen(a);
        a[l++]=' ';
        a[l]='\0';

        j=0;
        for(i=0;i<l;i++)
        {
            if(a[i]==' ')
            {
                k=(i-1);
                for(m=k;m>=j;m--)
                    cout<<a[m];

                if(i!=(l-1))
                cout<<" ";
                j=i+1;
            }
        }
        cout<<endl;
    }
    return 0;
}

Sunday, January 19, 2014

Download essential softwares for programming


>>Code::Blocks 


Download link :

Version : 16.01

For windows 32-bit :   Click Here
 
 

>>NetBeans IDE


Download link : 

Version : 8.0.2

For windows 32-bit/64-bit :   Click Here




>>Java Development Kit (JDK)

Download link : 

Version : 7

For windows 32-bit/64-bit :   Click Here




>>Text Pad


Download link :

Version : 7

For windows 32-bit :   Click Here

For windows 64-bit :   Click Here



>>Emulator 8086

Download link : 

Version : 4.08  (with registration key)

For windows 32-bit/64-bit :   Click Here


  

Tuesday, January 14, 2014

Download Bangla C Programming Books

> Book Name :   Computer Programming  (বাংলা)



Writer :   Tamim Shahriar Subeen

Download link :  Click Here


> Book Name :   Programming e Hatekhori  (বাংলা)

Writer :   Tamim Shahriar Subeen

Download link :   Click Here

Thursday, January 9, 2014

UVa 458 - The Decoder solution

Problem link :  UVa 458 - The Decoder

Solution :


#include<stdio.h>
#include<string.h>
int main()
{
    int i,l;
    char a[100005];
    while(gets(a))
    {
        l=strlen(a);
        for(i=0;i<l;i++)
            a[i]=a[i]-7;
        puts(a);
    }
    return 0;
}

UVa 382 - Perfection solution

Problem link :  UVa 382 - Perfection

Solution :


#include<stdio.h>
int main()
{
    int i,j,k,m,n,x=0;

    while(scanf("%d",&n)==1)
    {
        if(n==0)
            break;
        if(x!=1)
        printf("PERFECTION OUTPUT\n");
        x=1;

        m=0;
        for(i=1;i<=n/2;i++)
        {
            if(n%i==0)
                m+=i;
        }
        if(m==n)
            printf("%5d  PERFECT\n",n);
        else if(m>n)
            printf("%5d  ABUNDANT\n",n);
        else if(m<n)
            printf("%5d  DEFICIENT\n",n);
    }
    printf("END OF OUTPUT\n");
    return 0;
}

UVa 299 - Train Swapping solution

Problem link :  UVa 299 - Train Swapping

Solution :


#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a[55],i,j,m,n,p,t,tc;
    scanf("%d",&tc);
    for(t=1;t<=tc;t++)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
            cin>>a[i];
        m=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<n-1;j++)
            {
                if(a[j]>a[j+1])
                {
                    p=a[j];
                    a[j]=a[j+1];
                    a[j+1]=p;
                    m++;
                }
            }
        }
        printf("Optimal train swapping takes %lld swaps.\n",m);
    }
    return 0;
}
 

UVa 136 - Ugly Numbers solution

Problem link :  UVa 136 - Ugly Numbers

Solution : 


#include<stdio.h>
int main()
{
        printf("The 1500'th ugly number is 859963392.\n");
        return 0;
}

UVa 113 - Power of Cryptography solution

Problem link :  UVa 113 - Power of Cryptography

Solution :


#include<stdio.h>
#include<math.h>
int main()
{
    double n,p,i,j;
    while(scanf("%lf %lf",&n,&p)==2)
    {
        i=1/n;
        j=pow(p,i);
        printf("%.0lf\n",j);
    }
    return 0;
}