All pastes #180998 Raw Edit

Beyonder2

public java v1 · immutable
#180998 ·published 2006-09-24 11:55 UTC
rendered paste body
import java.io.*;import java.util.*;public class MainClass {	public static String readConsoleLine() {		char a;		String Out="";		try {		while (((a=(char)System.in.read())!=0) && (a!=13)) {			Out=Out+a;		}		System.in.read();		} catch (IOException e) {}		return Out;	}		private static class UFO {		int X,Y,Z;		int Count;				public UFO(int nX,int nY,int nZ,int nCount) {			X=nX;			Y=nY;			Z=nZ;			Count=nCount;		}				public static boolean isInt(int Val,int MinVal,int MaxVal) {			return ((Val>=MinVal) && (Val<=MaxVal));		}				public boolean isInSector(int MinX,int MaxX,int MinY,int MaxY,int MinZ,int MaxZ) {			return (isInt(X,MinX,MaxX)&&isInt(Y,MinY,MaxY)&&isInt(Z,MinZ,MaxZ));		}				public boolean samePos(UFO Other) {			return ((X==Other.X)&&(Y==Other.Y)&&(Z==Other.Z));		}	}		public static void removeFromList(UFO Coords) {		int Size=List.size();		for (int i=0;i<Size;i++)			if (List.get(i).samePos(Coords)) {				List.remove(i);				Size--;			}	}		public static int countCoordCount(UFO Coords) {		int Count=0;		for (UFO cur : List)			if (cur.samePos(Coords))				Count+=cur.Count;		return Count;	}		static ArrayList<UFO> List;	public static void main(String[] args) {		readConsoleLine();		List=new ArrayList<UFO>();		ArrayList<String> Output=new ArrayList<String>();		String[] Line;		while ((Line=readConsoleLine().split(" "))[0].equals("3")==false){			if (Line[0].equals("1")){				UFO New=new UFO(Integer.valueOf(Line[1]),Integer.valueOf(Line[2]),Integer.valueOf(Line[3]),Integer.valueOf(Line[4]));				if (New.Count<0) {					int TotalCount=countCoordCount(New)+New.Count;					if (TotalCount<0)						removeFromList(New);					else						List.add(New);				} else					List.add(New);			}			else if (Line[0].equals("2")) {				int Count=0;				int MinX=Integer.valueOf(Line[1]);				int MinY=Integer.valueOf(Line[2]);				int MinZ=Integer.valueOf(Line[3]);				int MaxX=Integer.valueOf(Line[4]);				int MaxY=Integer.valueOf(Line[5]);				int MaxZ=Integer.valueOf(Line[6]);				for (UFO Cur : List) {					if (Cur.isInSector(MinX, MaxX, MinY, MaxY, MinZ, MaxZ))						Count+=Cur.Count;				}				Output.add(String.valueOf(Count));			}		}		for (String a : Output) {			System.out.println(a);		}	}}