Interval beeCrowd 1037 URI Solution C Python programming coding solution solved explained formula loop easy what judge auto test bee Neilor Tonin braz
Interval
The formula is:
- Take input.
- Create a list of numbers that are given as intervals. The list will have one number once.
- Loop through the list.
- If the index is at 100 then it means it is out of range. Print "Fora de intervalo"
- If your input is zero or greater than your current index(loop value ex: i)," and it is less than the next index(ex:i+1). Print "Intervalo -->([<--i,i+1]" note that if the number is at the first interval you will have to print "(". For other intervals you will have to print "[".
N.B: "[" means include the first number. Whereas "(" means do not include the first number.
The solution in C:
#include <stdio.h>
int main() {
double x;
scanf("%lf",&x);
int listed[6] = {0,25,50,75,100,10000};
int i=0;
while(i<=4){
if(i==4){
printf("Fora de intervalo\n");
break;
}
if((x==0 || listed[i]<x) && x<=listed[i+1]){
if(i==0){
printf("Intervalo [%d,%d]\n",listed[i],listed[i+1]);
break;
} else{
printf("Intervalo (%d,%d]\n",listed[i],listed[i+1]);
break;
}
}
i++;
}
return 0;
}
The solution in Python:
x = float(input())
listed = [0,25,50,75,100,10000]
i=0;
while i<=4:
if i==4:
print("Fora de intervalo")
break
if (x==0 or listed[i]<x) and x<=listed[i+1]:
if i==0:
print("Intervalo [%d,%d]" % (listed[i],listed[i+1]))
break
else:
print("Intervalo (%d,%d]" % (listed[i],listed[i+1]))
break
i+=1
COMMENTS