URI 1035 Solve

Solve of URI 1035 (Selection Test 1) in C & C++


How to solve:
1.  In this problem, we need to check a little bit of complex condition ( Just Kidding :) ).

2. Input contains four integer numbers as A, B, C, & D.
3. Read the conditions carefully.
4. Conditions: If B is greater than C and D is greater than A; Summation of C and D is greater than summation of A and B; C and D are positive integers and A is an even number, then print "Valores aceitos" (That means accepted values).
5. Otherwise print "Valores nao aceitos" (That means values not accepted).

See sample input and output for better understanding with printing output.
Go through problem description and see my solution for clear concept. Thanks. :)


Solution in C:
//URI online judge 1035 solution in C
//This solution is made by Mehedi Hasan Kajol


#include<stdio.h>
int main(void){
    int a, b, c, d;
    scanf(" %d %d %d %d ", &a, &b, &c, &d);
    if( ( b>c && d>a ) && ( c+d > b+a ) && ( c>=0 && d>=0 ) && ( a%2 == 0 ) )
        printf("Valores aceitos\n");
    else
        printf("Valores nao aceitos\n");
    return 0;
}



Solution in C++:
//URI online judge 1035 solution in C++
//This solution is made by Mehedi Hasan Kajol



#include<iostream>

using namespace std;
int main(void){
    int a,b,c,d;

    cin >> a >> b >> c >> d;
    if( ( b>c && d>a ) && ( c+d > b+a ) && ( c>=0 && d>=0 ) && ( a%2 == 0 ) )
        cout << "Valores aceitos" << endl;
    else
        cout << "Valores nao aceitos" <<endl;
    return 0;
}

Post a Comment

Previous Post Next Post