Tuesday, 28 April 2020

Solution of URI 3065 :: Calculando


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.

#include <stdio.h>

int main()
{
    int m, test_case = 0;
    char str[1000];
    while(++test_case)
    {
        int i, ans = 0, num = 0, cndtn = 1;
        scanf("%d", &m);
        if(m == 0)
            break;
        scanf("%s", str);
        for(i=0; str[i]; i++)
        {
            if(str[i] == '-')
            {
                if(cndtn == 0) ans -= num;
                else ans += num;
                cndtn = 0; num = 0;
            }
            else if(str[i] == '+')
            {
                if(cndtn == 0) ans -= num;
                else ans += num;
                cndtn = 1; num = 0;
            }
            else if(str[i]>=48 && str[i]<=58)
                num = num*10+(str[i]-48);
        }
        if(cndtn == 0) ans -= num;
        else ans += num;

        printf("Teste %d\n", test_case);
        printf("%d\n\n", ans);
    }
    return 0;
}

Solution of URI 3055 :: Nota esquecida


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.

#include <stdio.h>

int main()
{
    int A, M;
    scanf("%d %d", &A, &M);
    int ans = (M*2) - A;
    printf("%d\n", ans);
    return 0;
}

Saturday, 18 April 2020

Solution of URI 2685 :: The Change


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.

#include <stdio.h>

int main()
{
    int x;
    while(scanf("%d", &x) != EOF)
    {
        x %= 360;
        if(x<90 && x>=0)
            printf("Bom Dia!!\n");
        else if(x>=90 && x<180)
            printf("Boa Tarde!!\n");
        else if(x>=180 && x<270)
            printf("Boa Noite!!\n");
        else if(x>=270 && x<360)
            printf("De Madrugada!!\n");
    }
    return 0;
}

Solution of URI 2344 :: Notas da Prova


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.

#include <stdio.h>

int main()
{
    int N;
    scanf("%d", &N);

    if(N >= 86)
        printf("A\n");

    else if(N >= 61 && N <= 85)
        printf("B\n");

    else if(N >= 36 && N <= 60)
        printf("C\n");

    else if(N >= 1 && N <= 35)
        printf("D\n");

    else
        printf("E\n");
    return 0;
}

Saturday, 5 May 2018

Solution of URI 2338 :: Morse


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, l, cndtn = 0;
    char str[1000*2], tmp[15];
    scanf("%d", &tst);
    for(i = 1; i<=tst; i++)
    {
        scanf("%s", str);
        for(j = 0; j < strlen(str) ;)
        {
            for(l = 0; ;l++)
            {
                if(str[j] == '=')
                {
                    tmp[l] = '=';
                    j += 1;
                }
                else if(str[j] == '.' && str[j+1] == '.' && str[j+3] == '.')
                {
                    j += 7;
                    tmp[l] = '\0';
                    cndtn = 1;
                    break;
                }
                else if((str[j] == '.' && str[j+1] == '.' && str[j+2] == '.'))
                {
                    j += 3;
                    tmp[l] = '\0';
                    break;
                }
                else
                {
                    tmp[l] = '.';
                    j += 1;
                }
                if(strlen(str) <= j)
                {
                    tmp[l+1] = '\0';
                    j += 1;
                    break;
                }
            }
            if(strcmp( tmp, "=.===") == 0) printf("a");
            else if(strcmp( tmp, "===.=.=.=") == 0) printf("b");
            else if(strcmp( tmp, "===.=.===.=") == 0) printf("c");
            else if(strcmp( tmp, "===.=.=") == 0) printf("d");
            else if(strcmp( tmp, "=") == 0) printf("e");
            else if(strcmp( tmp, "=.=.===.=") == 0) printf("f");
            else if(strcmp( tmp, "===.===.=") == 0) printf("g");
            else if(strcmp( tmp, "=.=.=.=") == 0) printf("h");
            else if(strcmp( tmp, "=.=") == 0) printf("i");
            else if(strcmp( tmp, "=.===.===.===") == 0) printf("j");
            else if(strcmp( tmp, "===.=.===") == 0) printf("k");
            else if(strcmp( tmp, "=.===.=.=") == 0) printf("l");
            else if(strcmp( tmp, "===.===") == 0) printf("m");
            else if(strcmp( tmp, "===.=") == 0) printf("n");
            else if(strcmp( tmp, "===.===.===") == 0) printf("o");
            else if(strcmp( tmp, "=.===.===.=") == 0) printf("p");
            else if(strcmp( tmp, "===.===.=.===") == 0) printf("q");
            else if(strcmp( tmp, "=.===.=") == 0) printf("r");
            else if(strcmp( tmp, "=.=.=") == 0) printf("s");
            else if(strcmp( tmp, "===") == 0) printf("t");
            else if(strcmp( tmp, "=.=.===") == 0) printf("u");
            else if(strcmp( tmp, "=.=.=.===") == 0) printf("v");
            else if(strcmp( tmp, "=.===.===") == 0) printf("w");
            else if(strcmp( tmp, "===.=.=.===") == 0) printf("x");
            else if(strcmp( tmp, "===.=.===.===") == 0) printf("y");
            else if(strcmp( tmp, "===.===.=.=") == 0) printf("z");
            if(cndtn == 1)
            {
                printf(" ");
                cndtn = 0;
            }
        }
        printf("\n");

    }
    return 0;
}