Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import org.json.simple.JSONObject;
- class Solution
- {
- public static void main(String [] args) throws Exception
- {
- Scanner sc = new Scanner(System.in);
- //Test Case Input
- int n = sc.nextInt();
- int[] arr = new int[n];
- for(int i = 0; i < n; i++) {
- arr[i] = sc.nextInt();
- }
- //Test Case Output
- int testMax = sc.nextInt();
- int testK = sc.nextInt();
- //Candidate's Output
- int candidateMax = sc.nextInt();
- int candidateK = sc.nextInt();
- double score = 0;
- boolean status = false;
- String message = "KRIVO RJESENJE!";
- if (candidateMax == testMax){
- if (candidateK == testK){
- score = 1;
- status = true;
- message = "Tocno! (ko sluzbeno)";
- } else {
- int k = candidateK;
- int correct = 1;
- long current = arr[0];
- for (int i = 1; i < n; ++i){
- if (arr[i] > arr[i - 1]){
- current += k;
- } else if (arr[i] < arr[i - i]){
- current -= k;
- }
- if (current == arr[i]){
- correct++;
- }
- }
- if (correct == candidateMax){
- score = 1;
- status = true;
- message = "Tocno! (drugaciji k)";
- } else {
- score = 0.5;
- status = false;
- message = "Pogodjen broj, ali krivi k";
- }
- }
- }
- status = true;
- score = 1;
- JSONObject obj = new JSONObject();
- obj.put("status", new Boolean(status));
- obj.put("message", message);
- obj.put("score", new Double(score));
- System.out.println(obj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement