Showing posts with label Ad-Hoc. Show all posts
Showing posts with label Ad-Hoc. Show all posts

Wednesday, 20 January 2016

Solution of URI 1300 :: UVA 12531 :: LIVE ARCHIVE 6138 :: Hours and Minutes


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int angle;
    while(scanf("%d", &angle)!= EOF)
    {
        if(angle%6==0) printf("Y\n");
        else printf("N\n");
    }
    return 0;
}

Solution of URI 1285 :: UVA 12527 :: LIVE ARCHIVE 6134 :: Different Digits


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int dgt(int x)
{
    int a,b=0;
    a=x;
    while(a)
    {
        a/=10;
        b++;
    }
    return b;
}
int main()
{
    int a,b,c,d,e,f,g,h,i,j,k,l,m,n;
    while(scanf("%d%d" ,&a, &b)!=EOF)
    {
        for(c=a,e=0; c<=b; c++)
        {
            d=dgt(c);
            if(d==1) e++;
            else if(d==2)
            {
                f=c%10;
                k=c/10;
                g=k%10;
                if(f!=g) e++;
            }
            else if(d==3)
            {
                f=c%10;
                k=c/10;
                g=k%10;
                l=k/10;
                h=l%10;
                if(f!=g && f!=h &&g!=h) e++;
            }
            else if(d==4)
            {
                f=c%10;
                k=c/10;
                g=k%10;
                l=k/10;
                h=l%10;
                j=l/10;
                i=j%10;
                if(f!=g && f!=h && f!=i && g!=h && g!=i && h!=i) e++;
            }
        }
        printf("%d\n",e);
    }
    return 0;
}


Solution of URI 1267 :: LIVE ARCHIVE 3470 :: Pascal Library


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int N, D,i,j,sum,k,l;
    while(1)
    {
        scanf("%d%d", &N, &D);
        if(N==0 && D==0) break;

        int ara[D][N];
        for(i=0; i<D; i++)
        {
            for(j=0; j<N; j++)
                scanf("%d", &ara[i][j]);
        }

        for(k=0; k<N; k++)
        {
            for(l=0,sum=0; l<D; l++)
                sum+=ara[l][k];
            if(sum==D)
            {
                printf("yes\n");
                break;
            }
            else sum=0;
        }
        if(sum==0) printf("no\n");
    }
    return 0;
}



Solution of URI 1140 :: UVA 12243 :: LIVE ARCHIVE 4810 :: Flowers Flourish from France


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <string.h>
int main()
{
    char str[1500];
    while(1)
    {
        gets(str);
        if(str[0]=='*') break;
        else
        {
            int lnth, i,j,cndtn=1;
            char cse[2];
            lnth=strlen(str);
            if(str[0]>=65 && str[0]<=90)
                cse[0]=str[0]+32;
            else if(str[0]>=97 && str[0]<=122)
                cse[0]=str[0]-32;
            for(i=1; i<lnth; i++)
            {
                if(str[i]==' ')
                {
                    if(str[i+1]==str[0] || str[i+1]==cse[0])
                        continue;
                    else{
                        cndtn=0;
                        break;
                    }
                }
            }
            if(cndtn==1) printf("Y\n");
            else printf("N\n");
        }
    }
    return 0;
}

Monday, 18 January 2016

Solution of URI 2016 :: D as in Daedalus


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int p, r, q;
    scanf("%d%d", &p, &r);
    q = p-1;
    int ara[q], bnk, b, cnt=0, sum=0, i, j, nit;
    for(i=1; i<=r; i++)
    {
        sum = 0;
        scanf("%d", &bnk);
        scanf("%d", &b);
        for(j=0; j<q; j++)
        {
            scanf("%d", &ara[j]);
            sum += ara[j];
        }
        if(sum>=bnk)
            continue;
        if(sum+b > bnk) b=0;
        nit = bnk - sum;
        if(bnk-sum>=10000) cnt += (10000 - b);
        else if((bnk-sum)>=1000) cnt += (1000 - b);
        else if((bnk-sum)>=100) cnt += (100 - b);
        else if((bnk-sum)>=10) cnt += (10 - b);
        else if((bnk-sum)>=1) cnt += (1- b);
    }
    printf("%d\n", cnt);
    return 0;
}

Solution of URI 1743 :: Automated Checking Machine


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f,A,B,C,D,E;
    scanf("%d%d%d%d%d", &a,&b,&c,&d,&e);
    scanf("%d%d%d%d%d", &A,&B,&C,&D,&E);
    if(a==A || b==B || c==C || d==D || e==E) printf("N\n");
    else printf("Y\n");
    return 0;
}

Tuesday, 5 January 2016