Advertisement
Guest User

CustomChecker

a guest
Feb 9th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. import java.io.*;
  2.  import java.util.*;
  3.  import org.json.simple.JSONObject;
  4.  class Solution
  5.  {
  6.      public static void main(String [] args) throws Exception
  7.      {
  8.          Scanner sc = new Scanner(System.in);
  9.  
  10.          //Test Case Input
  11.          int n = sc.nextInt();
  12.          int[] arr = new int[n];
  13.          for(int i = 0; i < n; i++) {
  14.              arr[i] = sc.nextInt();
  15.          }
  16.  
  17.         //Test Case Output
  18.          int testMax = sc.nextInt();
  19.          int testK = sc.nextInt();
  20.  
  21.          //Candidate's Output
  22.          int candidateMax = sc.nextInt();
  23.          int candidateK = sc.nextInt();
  24.  
  25.          double score = 0;
  26.          boolean status = false;
  27.          String message = "KRIVO RJESENJE!";
  28.  
  29.          if (candidateMax == testMax){
  30.              if (candidateK == testK){
  31.                  score = 1;
  32.                  status = true;
  33.                  message = "Tocno! (ko sluzbeno)";
  34.              } else {
  35.                  int k = candidateK;
  36.                  int correct = 1;
  37.                  
  38.                  long current = arr[0];
  39.                  for (int i = 1; i < n; ++i){
  40.                      if (arr[i] > arr[i - 1]){
  41.                          current += k;
  42.                      } else if (arr[i] < arr[i - i]){
  43.                          current -= k;
  44.                      }
  45.                      
  46.                      if (current == arr[i]){
  47.                          correct++;
  48.                      }
  49.                  }
  50.                  
  51.                  if (correct == candidateMax){
  52.                      score = 1;
  53.                      status = true;
  54.                      message = "Tocno! (drugaciji k)";
  55.                  } else {
  56.                      score = 0.5;
  57.                      status = false;
  58.                      message = "Pogodjen broj, ali krivi k";
  59.                  }
  60.              }
  61.          }
  62.  
  63.          status = true;
  64.          score = 1;
  65.          
  66.          JSONObject obj = new JSONObject();
  67.          obj.put("status", new Boolean(status));
  68.          obj.put("message", message);
  69.          obj.put("score", new Double(score));
  70.          System.out.println(obj);
  71.  
  72.      }
  73.  
  74.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement