Showing posts with label UVA. Show all posts
Showing posts with label UVA. Show all posts

Monday, 3 October 2016

Solution of UVA 10474 :: Where is the Marble?


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 num, rnd, tst =0, tmp, tmp2, i, j, cnt;
    int ara[10001];
    while(1)
    {
        for(i=0; i<10001; i++) ara[i]=0;
        scanf("%d%d", &num, &rnd);
        if(num == 0 && rnd == 0) break;
        for(i=0; i<num; i++)
        {
            scanf("%d", &tmp);
            ara[tmp]++;
        }
        printf("CASE# %d:\n", ++tst);
        for(i=1; i<=rnd; i++)
        {
            scanf("%d", &tmp2);
            if(ara[tmp2]>0)
            {
                for(j=1, cnt=1; j<tmp2; j++) cnt += ara[j];
                printf("%d found at %d\n", tmp2, cnt);
            }
            else printf("%d not found\n", tmp2);
        }
    }
    return 0;
}

Wednesday, 20 January 2016

Solution of URI 1323 :: UVA 12149 :: LIVE ARCHIVE 4215 :: Feynman


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;
    while(1)
    {
        scanf("%d", &a);
        if(a==0) break;
        else b=(a*(a+1)*((2*a)+1))/6;
        printf("%d\n",b);
    }
    return 0;
}


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 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 UVA 13007 :: LIVE ARCHIVE 7206 :: 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;
    while(scanf("%d%d", &p, &r)!=EOF)
    {
        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 UVA 12854 :: LIVE ARCHIVE 6821 :: 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;
    while(scanf("%d %d %d %d %d %d %d %d %d %d", &a,&b,&c,&d,&e,&A,&B,&C,&D,&E)!=EOF)
    {
    if(a==A || b==B || c==C || d==D || e==E) printf("N\n");
    else printf("Y\n");
    }
    return 0;
}


Wednesday, 13 January 2016

Solution of UVA 13012 :: LIVE ARCHIVE 7211 :: Identifying Tea


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 Rahamnir Rahim.**/

#include <stdio.h>
int main()
{
    int n, m , i, cnt=0;
    while(scanf("%d", &n)!=EOF)
    {
        for(i=0, cnt=0; i<5; i++)
        {
            scanf("%d", &m);
            if(m==n) cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}

Saturday, 9 January 2016

Solution of UVA 1225 :: Digit Counting


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 tst, i, j, k;
    scanf("%d", &tst);
    while(tst--)
    {
        int n, ara[10];
        for(i=0; i<10; i++) ara[i]=0;
        scanf("%d", &n);
        for(i=1; i<=n; i++)
        {
            j = i;
            while(j!=0)
            {
                k=j%10;
                ara[k]++;
                j/=10;
            }
        }
        for(i=0; i<9; i++) printf("%d ", ara[i]);
        printf("%d\n", ara[9]);
    }
    return 0;
}

Tuesday, 5 January 2016

Monday, 4 January 2016