SHARE
TWEET

Untitled

a guest Oct 21st, 2019 87 in 3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package problem_Solving;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.List;
  7. import java.util.stream.IntStream;
  8.  
  9. import static java.util.stream.Collectors.toList;
  10.  
  11. class Result {
  12.  
  13.     /*
  14.      * Complete the 'gradingStudents' function below.
  15.      *
  16.      * The function is expected to return an INTEGER_ARRAY.
  17.      * The function accepts INTEGER_ARRAY grades as parameter.
  18.      */
  19.  
  20.     public static List<Integer> gradingStudents(List<Integer> grades) {
  21.         int value;
  22.         int count = 0;
  23.         for (int i = 0; i < grades.size(); i++) {
  24.             if (grades.get(i) < 0 || grades.get(i) > 100) continue;
  25.             if (grades.get(i) < 38) {
  26.                 System.out.println(grades.get(i));
  27.             } else if (grades.get(i) >= 38) {
  28.                 value = grades.get(i) % 10;
  29.                 for (int j = 0; j < 10; j++) {
  30.                     if (value % 5 == 0) break;
  31.                     value++;
  32.                     count++;
  33.                 }
  34.                 if (count < 3) {
  35.                     System.out.println(grades.get(i) + count);
  36.                     grades.set(i, grades.get(i) + count);
  37.                 } else {
  38.                     System.out.println(grades.get(i));
  39.                 }
  40.             } else {
  41.                 System.out.println(grades.get(i));
  42.             }
  43.             //value = 0;
  44.             count = 0;
  45.         }
  46.         return grades;
  47.     }
  48. }
  49.  
  50. /*
  51. 4
  52. 73
  53. 67
  54. 38
  55. 33
  56.  
  57. Sample Output 0
  58.  
  59. 75
  60. 67
  61. 40
  62. 33
  63.  
  64.  
  65.  */
  66.  
  67.  
  68. public class GradingStudents {
  69.     public static void main(String[] args) throws IOException {
  70.         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  71.         //BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
  72.  
  73.         int gradesCount = Integer.parseInt(bufferedReader.readLine().trim());
  74.  
  75.         List<Integer> grades = IntStream.range(0, gradesCount).mapToObj(i -> {
  76.             try {
  77.                 return bufferedReader.readLine().replaceAll("\\s+$", "");
  78.             } catch (IOException ex) {
  79.                 throw new RuntimeException(ex);
  80.             }
  81.         })
  82.                 .map(String::trim)
  83.                 .map(Integer::parseInt)
  84.                 .collect(toList());
  85.  
  86.         List<Integer> result = Result.gradingStudents(grades);
  87.  
  88.         /*bufferedWriter.write(
  89.                 result.stream()
  90.                         .map(Object::toString)
  91.                         .collect(joining("\n"))
  92.                         + "\n"
  93.         );*/
  94.  
  95.         bufferedReader.close();
  96.         //bufferedWriter.close();
  97.     }
  98. }
  99.  
  100. /*
  101. Grading Students
  102. HackerLand University has the following grading policy:
  103. Every student receives a grade in the inclusive range from 0  to 100.
  104. Any grade less than 40 is a failing grade.
  105. Sam is a professor at the university and likes to round each student's grade according to these rules:
  106. If the difference between the grade and the next multiple of 5 is less than 3 , round grade up to the
  107. next multiple of 5.
  108. If the value of grade is less than 38 , no rounding occurs as the result will still be a failing grade.
  109. For example, grade = 84  will be rounded to 85  but grade = 29 will not be rounded because the
  110. rounding would result in a number that is less than 40
  111. .
  112. Given the initial value of grade  for each of Sam's n students, write code to automate the rounding process.
  113.  
  114. Function Description
  115.  
  116. Complete the function gradingStudents in the editor below. It should return an integer array consisting of rounded grades.
  117.  
  118. gradingStudents has the following parameter(s):
  119.  
  120.     grades: an array of integers representing grades before rounding
  121.  
  122. Input Format
  123.  
  124. The first line contains a single integer, n  , the number of students.
  125. Each line i of the n subsequent lines contains a single integer,grades[i] , denoting student i's grade.
  126.  
  127. Constraints
  128. 1<= n <= 60
  129. 0 <= grades[i] <= 100
  130. Output Format
  131.  
  132. For each grades[i], print the rounded grade on a new line.
  133.  
  134. Sample Input 0
  135.  
  136. 4
  137. 73
  138. 67
  139. 38
  140. 33
  141.  
  142. Sample Output 0
  143.  
  144. 75
  145. 67
  146. 40
  147. 33
  148.  
  149. Explanation 0
  150.  
  151. ID  Original Grade   Final Grade
  152.  
  153. 1       73             75
  154. 2       67             67
  155. 3       38             40
  156. 4       33             33
  157.  
  158. image
  159.  
  160.     Student 1 received a 73, and the next multiple of 5 from 73 is 75. Since 75 - 73 < 3, the student's grade is rounded to 75.
  161.     Student 2 received a 67 , and the next multiple of 5 from 67 is 70. Since 70 - 67 = 3, the grade will not be modified and the student's final grade is 67.
  162.     Student 3 received a 38, and the next multiple of 5 from 38 is 40 . Since 40 - 38 < 3, the student's grade will be rounded to 40.
  163.     Student 4 received a 33 grade below 38 , so the grade will not be modified and the student's final grade is 33 .
  164.  
  165.            */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top