Tuesday, May 31, 2016

URI Online Judge Solution 1113 || Ascending and Descending

URI Online Judge | 1113

Ascending and Descending

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read an undetermined number of pairs of integer values. Write a message for each pair indicating if this two numbers are in ascending or descending order.

Input

The input file contains several test cases. Each test case contains two integer numbers X and Y. The input will finished when X = Y.

Output

For each test case print “Crescente”, if the values X and Y are in ascending order, otherwise print “Decrescente”.
Input SampleOutput Sample
5 4
7 2
3 8
2 2
Decrescente
Decrescente
Crescente


URI Online Judge Solution 1113 || Ascending and Descending in JAVA


import java.io.IOException;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        int X, Y;
 
        Scanner input = new Scanner(System.in);
 
        do {
 
            X = input.nextInt();
            Y = input.nextInt();
            if (X > Y) {
                System.out.print("Decrescente\n");
            } else if (X < Y) {
                System.out.print("Crescente\n");
            }
        } while (X != Y);
 
    }
}


URI Online Judge Solution 1113 || Ascending and Descending in C


#include<stdio.h>
int main(){
    int X, Y;

    do {

        scanf("%d%d", &X, &Y);
        if (X > Y) {
            printf("Decrescente\n");
        } else if (X < Y) {
            printf("Crescente\n");
        }
    } while (X != Y);

}


URI Main question link
See Code in Dropbox

Read More

URI Online Judge Solution 1101 || Sequence of Numbers and Sum

URI Online Judge | 1101

Sequence of Numbers and Sum

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read an undetermined number of pairs values and N (stop when any of these values is less or equal to zero). For each pair, print the sequence from the smallest to the biggest (including both) and the sum of consecutive integers between them (including both).

Input

The input file contains pairs of integer values and N. The last line of the file contains a number zero or negative, or both.

Output

For each pair of numbers, print the sequence from the smallest to the biggest and the sum of these values, as shown below.
Input SampleOutput Sample
5 2
6 3
5 0
2 3 4 5 Sum=14
3 4 5 6 Sum=18

URI Online Judge Solution 1101 || Sequence of Numbers and Sum in JAVA


import java.io.IOException;
import java.util.Scanner;
  

public class Main {
  
    public static void main(String[] args) throws IOException {
  
       int X, Y;
        Scanner input =new Scanner(System.in);
         
        while (((X = input.nextInt()) > 0 )&&((Y = input.nextInt()) > 0 )) {
            int sum = 0;
            if (X > Y) {
                for (Y = Y; Y <= X; Y++) {
                    sum+=Y;
                    System.out.print(Y+" ");
                }
                System.out.print("Sum="+sum+"\n");
            }else {
                for (X = X; X <= Y; X++) {
                    sum+=X;
                    System.out.print(X+" ");
                }
                System.out.print("Sum="+sum+"\n");
            }
        }
  
    }
  
}


URI Online Judge Solution 1101 || Sequence of Numbers and Sum in C


#include<stdio.h>
int main(){
    int X, Y;

    while (((scanf("%d", &X)) > 0 )&&(((scanf("%d", &Y)) > 0 ))) {
        int sum = 0;
        if (X > Y) {
            for (Y = Y; Y <= X; Y++) {
                sum+=Y;
                printf("%d ", Y);
            }
            printf("Sum=%d\n", sum);
        }else {
            for (X = X; X <= Y; X++) {
                sum += X;
                printf("%d ", X);
            }
            printf("Sum=%d\n", sum);
        }
    }
}


URI Main Question link
Download dropbox code


Some Description about the problem:

Using a simple for loop I've just solve the problem.
Look in the line

for (Y = Y; Y <= X; Y++) {
                    sum+=Y;
                    System.out.print(Y+" ");
                }

Here from two input range I've calculated the summation.

Note : 

It is hardly required that you have to give all of the format what user can give the input. That means look-

 if else statement








Read More

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.