Algorithm
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1113
Ascending and Descending
Adapted by Neilor Tonin, URI Brazil
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 Sample | Output Sample |
5 4 |
Decrescente |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
int x, y;
cin >> x >> y;
if (x == y){
break;
}
if (x > y){
cout << "Decrescente" << endl;
}
else{
cout << "Crescente" << endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Java Programming
Code -
Java Programming
import java.io.IOException;
import java.util.Scanner;
public class Main{
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
while (true) {
int x = input.nextInt();
int y = input.nextInt();
if (x == y){
break;
}
if (x > y){
System.out.println("Decrescente");
}
else{
System.out.println("Crescente");
}
}
}
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
// var lines = input.split('\n');
var sep = [' ', '\n'];
// console.log(separators.join('|'));
var line = input.split(new RegExp(sep.join('|'), 'g'));
while (true){
var x = parseInt(line.shift());
var y = parseInt(line.shift());
if (x === y){
break;
}
if (x > y){
console.log("Decrescente");
}
else{
console.log("Crescente");
}
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
while(True):
x, y = map(int, input().split(" "))
if (x == y):
break
if (x > y):
print("Decrescente")
else:
print("Crescente")
Copy The Code &
Try With Live Editor
Input
Output