Review problem - 5 (Logic Building - Getting started with java)
Assess your performance by solving these problems on your own!
There are 10 problems in a contest. You know that the score of each problem is either 1 or 100 points.
Chef came to know the total score of a participant and he is wondering how many problems were actually solved by that participant.
Given the total score P of the participant, determine the number of problems solved by the participant. Print −1 in case the score is invalid.
Input
5 103 0 6 142 1000
Output
4 0 6 -1 10
My Code
// Update the code below to solve this problem
import java.util.Scanner;
class Codechef
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int p, s=0, rem;;
int t = sc.nextInt();
for(int i=0; i<t; i++)
{
p = sc.nextInt();
if(p>=0 && p<100){
if(p<=10){
s = p;
}
else{
s = -1;
}
}
else if(p>=100 && p<=1000){
rem = p%100;
s = p/100;
if(rem<10){
s = s+rem;
}
else{
s=-1;
}
}
else{
s=-1;
}
System.out.println(s);
t--;
}
}
}