/*
* using big integer solved the problem.
* dont know the problem with ur code.
* Try this.
BigInteger product = new BigInteger("0");
BigInteger first = new BigInteger("0");
BigInteger second = new BigInteger("0");
for(int i=0;i<atomList.length;i++)
{
first=new
BigInteger(Integer.toString(atomList[i]));
second=new
BigInteger(Integer.toString(atomList2[(atomList.length-1)-i]));
product=product.add(first.multiply(second));
}
*/
here is the full code
import java.util.Arrays;
import java.text.NumberFormat;
import java.text.*;
import java.math.*;
public class Scalar
{
public static void main(String args[])
{
Literate lit = new Literate("A-large-practice.in","scalar-big-
out-bi.out",10000);
int atomList[]=new int[1000];
int atomList2[]=new int[1000];
int lineNo=-2;
int caseNo=0;
String str="";
int upper=0;
while ((str = lit.readLine()) != null)
{
lineNo+=1;
if(lineNo==-1||lineNo==-2) continue;
if(lineNo%3==0){ }
if(lineNo%3==1) {
atomList=lit.splitInt(str);
upper=atomList.length;
}
if(lineNo%3==2){
//System.out.println("this is to be split" + str);
caseNo+=1;
String ans="";
atomList2=lit.splitInt(str);
Arrays.sort(atomList);
Arrays.sort(atomList2);
BigInteger product = new BigInteger("0");
BigInteger first = new BigInteger("0");
BigInteger second = new BigInteger("0");
for(int i=0;i<atomList.length;i++)
{
first=new
BigInteger(Integer.toString(atomList[i]));
second=new
BigInteger(Integer.toString(atomList2[(atomList.length-1)-i]));
product=product.add(first.multiply(second));
}
ans=lit.giveAns(caseNo)+product;
lit.writeln(ans);
System.out.println(ans);
}
}
}
}
~~~~~~~~~~~~~~
//literate class
import java.io.*;
public class Literate
{
BufferedReader in;
BufferedWriter out;
String writeFile;
int size;
public Literate(String readFile,String writeFile)
{
this(readFile,writeFile,2000);
}
public Literate(String readFile,String writeFile,int size)
{
this.size=size;
this.writeFile=writeFile;
if(readFile!=null)
{
try
{
in = new BufferedReader(new FileReader(readFile));
}
catch(IOException e)
{
System.out.println("error occured in readFile
initialization");
}
}//if
if(writeFile!=null)
{
try
{
out = new BufferedWriter(new FileWriter(writeFile, true));
}
catch(IOException e)
{
System.out.println("error occured in writeFile
initialization");
}
}
}
public void close()
{
try
{
out.close();
}
catch(Exception e ){
System.out.println("error in out.close");
}
}
public void writeln(String sent)
{
try {
BufferedWriter out = new BufferedWriter(new
FileWriter(writeFile, true));
out.write(sent);
out.write("\n");
out.close();
}
catch (IOException e) {
System.out.println("error in writeln");
}
}
public void write(String sent)
{
try {
BufferedWriter out = new BufferedWriter(new
FileWriter(writeFile, true));
out.write(sent);
out.close();
}
catch (IOException e) {
System.out.println("error in write");
}
}
public String readLine()
{
try
{
return in.readLine();
}
catch(IOException e)
{
System.out.println("error in readLine");
}
return null;
}
public String[] split(String sent)
{
String[] atomList = sent.split(" ");
return atomList;
}
public String giveAns(int caseNo)
{
return "Case #"+caseNo+": ";
}
public int[] splitInt(String sent)
{
String[] atomList = sent.split(" ");
int[] intList = new int[atomList.length];
int counter=0;
for(String s: atomList)
{
intList[counter]=Integer.parseInt(s);
counter++;
}
return intList;
}
public static void main(String[] args)
{
}
}
On Apr 26, 8:33 pm, Seydou TAPSOBA <[email protected]> wrote:
> I don't know what is the matter with this code but the large input doesn't
> worh
>
> this is my code in java
>
> import java.io.File;
> import java.io.FileNotFoundException;
> import java.io.PrintWriter;
> import java.math.BigInteger;
> import java.util.Arrays;
> import java.util.Scanner;
>
> public class scalar1 {
>
> public static void main(String[] args) throws FileNotFoundException {
>
> //Scanner in = new Scanner(new File("A-small-practice.in"));
> Scanner in = new Scanner(new File("A-large-practice.in"));
> PrintWriter out = new PrintWriter(new File("minimumBig.out"));
>
> int cas = 1;
> BigInteger resultat = BigInteger.ZERO;
>
> int T = in.nextInt();
> int dim = 0;
>
> int u[];
> int v[];
>
> while(in.hasNext()) {
>
> dim = in.nextInt();
> u = new int[dim];
> v = new int[dim];
>
> for (int i = 0; i < dim; i++) {
> u[i] = in.nextInt();
> }
> for (int i = 0; i < dim; i++) {
> v[i] = in.nextInt();
> }
>
> Arrays.sort(u);
> Arrays.sort(v);
> for (int i = 0; i < v.length; i++) {
> long temp = u[i]*v[dim-i-1];
>
> resultat = resultat.add(new BigInteger(""+temp));
>
> }
>
> out.print("Case #"+cas+": ");
> out.print(resultat);
> if(in.hasNext())out.println();
> cas++;
> resultat = BigInteger.ZERO;
> }
> out.close();
>
> }
>
>
>
>
>
>
>
> }
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.