Saturday 16 July 2016

Solution of URI 2139 :: Pedrinho's Christmas


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 month, day, x, i;
    int ara[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 25};
    while(scanf("%d%d", &month, &day) != EOF)
    {
        if(month == 12 && day == 25) printf("E natal!\n");
        else if(month == 12 && day > 25) printf("Ja passou!\n");
        else if(month == 12 && day == 24) printf("E vespera de natal!\n");
        else
        {
            x = ara[month-1] - day;
            for(i = month; i < 12; i++)
                x += ara[i];
            printf("Faltam %d dias para o natal!\n", x);
        }
    }
    return 0;
}

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. this is not URI 2136...this is URI 2139

    ReplyDelete
  4. Qual é o erro do meu codigo?

    #include
    #include

    int main()
    {
    int mes = 0;
    int dia = 0;

    while(scanf("%d %d",&mes,&dia) != EOF){

    if( mes == 12){

    if( dia == 24 )
    printf("E vespera de natal!\n");
    if( dia == 25 )
    printf("E natal!\n");
    if( dia > 25 )
    printf("Ja passou!\n");
    if( dia <= 23 ){
    printf("Faltam %d dias para o natal!\n",(( 25 - dia ) ));
    }

    }

    if( mes == 11 ){

    printf("Faltam %d dias para o natal!\n",( (12 - mes) * 30 + ( 25 - dia ) ));

    }

    if( mes <= 10 ){

    printf("Faltam %d dias para o natal!\n",( (12 - mes) * 30 + ( 30 - dia ) ));

    }

    }

    return 0;
    }

    ReplyDelete

Note: only a member of this blog may post a comment.