She will not be able to share her code because she is getting NZEC on Xor again question May’18. She is searching common ways she can use to get rid of.
package com.nec.hacker;
import java.util.Arrays;
import java.util.Scanner;
class SweetsHacker {
private static Scanner scan;
public static void main(String[] args) {
scan = new Scanner(System.in);
System.out.println("Number of Test Cases please ?");
int testCases = scan.nextInt();
scan.nextLine();
int totalAmount = 0;
int remainder = 0;
int quoteint = 0;
int sum = 0;
while (testCases > 0) {
System.out
.println("Number of bank notes given by customer & the value of sweets");
String[] bankNotesNoAndCostOfSweet = scan.nextLine().split(" ");
System.out.println("Cost of "+bankNotesNoAndCostOfSweet[0]+" sweets ? " );
String[] bankNotesValue = scan.nextLine().split(" ");
int[] bankNotesValueIntArray = Arrays.asList(bankNotesValue)
.stream().mapToInt(Integer::parseInt).toArray();
java.util.Arrays.sort(bankNotesValueIntArray);
for (int i = 0; i < bankNotesValue.length; i++) {
totalAmount = totalAmount + Integer.valueOf(bankNotesValue[i]);
}
if (totalAmount > 0) {
remainder = totalAmount
% Integer
.valueOf(bankNotesNoAndCostOfSweet[bankNotesNoAndCostOfSweet.length - 1]);
}
if (remainder > 0) {
sum = totalAmount - Integer.valueOf(bankNotesValueIntArray[0]);
if (sum
/ Integer
.valueOf(bankNotesNoAndCostOfSweet[bankNotesNoAndCostOfSweet.length - 1]) == totalAmount
/ Integer
.valueOf(bankNotesNoAndCostOfSweet[bankNotesNoAndCostOfSweet.length - 1])) {
System.out.println("-1");
} else {
System.out.println("1");
}
}
printQuoteint(quoteint, bankNotesNoAndCostOfSweet, remainder,
bankNotesValue, totalAmount);
// checkForSmallerRemainder(totalAmount,bankNotesValue,remainder);
testCases--;
}
}
private static void printQuoteint(int quoteint,
String[] bankNotesNoAndCostOfSweet, int remainder,
String[] bankNotesValue, int totalAmount) {
// TODO Auto-generated method stub
if (remainder == 0) {
quoteint = totalAmount
/ Integer
.valueOf(bankNotesNoAndCostOfSweet[bankNotesNoAndCostOfSweet.length - 1]);
System.out.println(quoteint);
}
}
}
Getting NZEC error here also.Although works like a charm in my PC.
NZEC might occur because sometimes your code must not be getting passed for all possible types of Test Cases. Please understand the problem statement and try to run your code with various scenarios. There is a possibility that the code might be failing for a particular Test case.
It has happened with me, as well. I found out that my code wasn’t working for a particular TC. I changed my code logic accordingly and NZEC error did’t occur.
Codechef accepted my solution.
So please design your code that handles as many varieties of Test cases as possible.
try to provide input like this
int y;
if(sc.hasNextInt) y=nextInt;
//with all data types
//sc is instance of scanner class
Try running the code with input if you are using java platform.It will not produce that error with input .Try it and let me know if it works.