Created
May 14, 2012 07:44
-
-
Save bknarendra/2692514 to your computer and use it in GitHub Desktop.
CoderCharts:Sum It Up 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For java, make sure the main class name is sum_it_4 | |
import java.io.*; | |
import java.util.*; | |
public class sum_it_4 | |
{ | |
public static void main(String[] args) throws Exception { | |
Scanner sc=new Scanner(new File(args[0])); | |
Vector <Integer>v=new Vector<Integer>(); | |
int i=0,j,k; | |
while(Boolean.TRUE) | |
{ | |
v.add(sc.nextInt()); | |
if(sc.hasNext()) sc.nextLine(); | |
else break; | |
} | |
int n=(int)Math.sqrt(v.size()); | |
int a[][]=new int[n][n]; | |
k=0; | |
for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=(Integer)v.elementAt(k++).intValue(); | |
int l,b,c,max=-9999,d=0; | |
for(i=0;i<n;i++) | |
for(j=0;j<n;j++) | |
for(k=i;k<n;k++) | |
for(l=j;l<n;l++) | |
{ | |
for(b=i;b<=k;b++) | |
for(c=j;c<=l;c++) | |
d+=a[b][c]; | |
if(max<d) | |
max=d; | |
d=0; | |
} | |
System.out.println(max); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment