id
stringlengths
36
36
text
stringlengths
1
1.25M
a60c6cc9-22dc-496b-93cd-10ea4e0cba89
public double getTotalWeightItems() { double peso = 0D; for(Item item : mochila){ peso += item.getWeight(); } return peso; }
beac1c07-ac9c-4ab0-8e5b-e8aca5b319b6
public void take(Command command){ if (!command.hasSecondWord()){ System.out.println("take what?"); return; } String id = command.getSecondWord(); Item item = currentRoom.getItem(id); if(item != null) { if(item.canBeTaken()){ ...
98bd427d-195d-4421-8229-53c32d61b501
public void drop(Command command) { if (!command.hasSecondWord()){ System.out.println("drop what?"); return; } String id = command.getSecondWord(); int index = 0; boolean searching = true; while( searching && index < mochila.size()){ Item it...
032796c9-4c7f-441e-9222-9a92e3a27c94
public Command(String firstWord, String secondWord) { commandWord = firstWord; this.secondWord = secondWord; }
7e466ffe-df77-4470-b0a9-edfa34970949
public String getCommandWord() { return commandWord; }
9573fb22-681e-411a-918e-93b5e3140688
public String getSecondWord() { return secondWord; }
c68aa79c-ba64-427a-8e0b-4844f118efcc
public boolean isUnknown() { return (commandWord == null); }
dee52cc5-46a2-47b3-ab8f-14e13625902f
public boolean hasSecondWord() { return (secondWord != null); }
1570473d-71e9-4f11-baa5-683b04a6ea00
public static void main(String[] args) { int m=0; int p=0; for(int i=999;i>m;i--) for(int j=999;j>i;j--) if(isp(j*i)) { p=Math.max(i*j,p); m=p/1000; } System.out.println(p); }
6498d7f2-c123-419d-ac34-316620e4f925
private static boolean isp(int n) { if(n%10!=n/100000) return false; if((n/10)%10!=(n/10000)%10) return false; if((n/100)%10!=(n/1000)%10) return false; return true; }
224a4c7c-1ada-4add-a9e4-560306bef329
public static void main(String[] args) { for(int i=0;i<300;i++) for(int j=i;j<500;j++) if(Math.sqrt(i*i+j*j)==1000-i-j) { System.out.println(i+" "+j+" "+(1000-i-j)+" "+i*j*(1000-i-j)); System.exit(0); } }
3c8ed466-91ad-417e-aa68-3bf2bc508ca2
public static void main(String[] args) { int[][] a= {{8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8}, {49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0}, {81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65}, {52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91}, {22,31,16,71,51...
c48c8e5a-ddd9-48af-a22e-202dc66ec904
public static void main(String[] args) { String s="731671765313306249192251196744265747423553491949349698352031277450632623957831801698480186947885184385861560789112949495459501737958331952853208805511125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311362229893423380308...
70203ec6-00cb-47c9-a3ba-13e793a6c7f2
public static void main(String[] args) { int n=28123; boolean[] a=new boolean[n]; boolean[] b=new boolean[n]; for(int i=1;i<n;i++) { int s=1; int l=(int)Math.sqrt(i); for(int j=2;j<=l;j++) { int d=i/j; if(d==i/(double)j) { s+=j; s+=(d==j?0:d); } } a[i-1]=i<s; } // for(int...
747c39d3-336e-4f4c-96e1-6ada9c7843ae
public static void main(String[] args) { int n=20; long[][] a=new long[n][]; for(int i=0;i<n;i++) a[i]=new long[n]; for(int i=0;i<n;i++) { a[i][0]=i+2; a[0][i]=a[i][0]; } for(int i=1;i<n;i++) for(int j=1;j<=i;j++) { a[i][j]=a[i-1][j]+a[i][j-1]; a[j][i]=a[i][j]; } System.out.println(...
0e1f246a-9981-4d74-89cc-05b706e03918
public static void main(String[] args) { int[] p= {2,3,5,7,11,13,17,19}; int[] n=new int[p.length]; for(int i=0;i<n.length;i++) n[i]=0; for(int i=2;i<20;i++) for(int j=0;j<p.length;j++) if(div(i,p[j])>n[j]) n[j]=div(i,p[j]); int mul=1; for(int i=0;i<p.length;i++) for(int j=0;j<n[i];j++) ...
003ab889-dee3-46ee-ae69-a684c651493f
private static int div(int num, int prime) { int i=-1; do { num/=prime; i++; }while(num>0); return i; }
defea912-6872-4e41-960f-13bd49eef61e
public static void main(String[] args) { int[][] a=new int[3][]; for(int i=0;i<3;i++) a[i]=new int[6]; for(int i=0;i<3;i++) for(int j=0;j<6;j++) a[i][j]=0; System.out.println(test(a,0)/6); }
5c026650-4dd0-4715-84cb-617eb18882a4
private static int test(int[][] t, int i) { // System.out.println(i); int co=0; for(int a=1;a<N;a++) { t[i][0]=a; for(int b=a;b<N;) { t[i][1]=b; for(int c=b;c<N;c++) { t[i][2]=c; for(int d=c;d<N;d++) { t[i][3]=d; for(int e=d;e<N;e++) { t[i][4]=e; for(int f=e;f<N;f+...
5f35555a-8a13-40b9-b19a-10842c9d26b5
private static int turn(int[][] a) { for(int i=0;i<3;i++) if(chance(a[i],a[(i+2)%3])<=.5 && chance(a[i],a[(i+1)%3])<=.5) return 0; return 1; }
261a752a-571d-478a-8cf9-e19fdbda581e
private static double chance(int[] a,int[] b) { int wi=0; for(int i=0;i<6;i++) for(int j=0;j<6;j++) if(a[i]>b[j]) wi++; return wi/36.0; }
91266a42-c992-4cf3-ae7a-22426af3b092
public static void main(String[] args) { //TODO long sum = 2; long f=1; long s=2; long c; do { c=f+s; if(c%2==0) { sum+=c; System.out.println(c); } f=s; s=c; // System.out.println(c); }while(c<4000000); // if(c%2==1 && c>4000000) // sum-=c; System.out.println(sum); }
27120c60-de75-47bf-9429-495e50910b99
public static void main(String[] args) { int[] a=new int[700]; for(int i=1;i<700;i++) test(a,i); int c=0; for(int i=2;i<10000000;i++) if(a[sqr(i)]==89) c++; System.out.println(c); }
2c1222a3-1d81-4202-b1c4-6c3b44eff98a
private static int test(int[] a, int i) { if(a[i]>0) return a[i]; if(i==89) { a[i]=89; return 89; } if(i==1) { a[i]=1; return 1; } a[i]=test(a,sqr(i)); return a[i]; }
8b52f7ea-501f-42e3-a8d5-6622de668851
private static int sqr(int i) { int s=0; do { s+=(i%10)*(i%10); i/=10; }while(i!=0); return s; }
126538bc-8ddd-4fd8-bae2-58ba1686323a
public static void main(String[] args) { long num=600851475143L; long max = (long) Math.sqrt(num); if(max%2==0) max--; for(;max>0;max-=2) if(num%max==0) { boolean p = true; long s=(long) Math.sqrt(max); if(s%2==0) s--; for(;s>2;s-=2) if(max%s==0) { p=false; break; ...
b0d5bd25-8547-4155-ad34-2cf580da46af
public static void main(String[] args) { Scanner in = new Scanner(System.in); int max = in.nextInt(); int sum=0; for(int i=1;i<max;i++) if(i%3==0 || i%5==0) sum+=i; System.out.println(sum); }
cd12213b-502f-41fa-9974-23e093b36d87
public static void main(String[] args) { int m=1000000; int[] n=new int[m]; for(int i=0;i<m;i++) n[i]=0; int t=1; for(int i=2;i<m;i++) if(test(n,i)>n[t]) t=i; System.out.println(t); }
1c26ae89-7ba9-4e44-ad3f-218f00a48f0f
private static int test(int[] n, long i) { if(i==1) return 0; if(i>=1000000) { if(i%2==0) return test(n,i/2)+1; return test(n,3*i+1)+1; } if(n[(int) i]>0) return n[(int) i]; if(i%2==0) { n[(int) i]=test(n,i/2)+1; return n[(int) i]; } else { n[(int) i]=test(n,3*i+1)+1; return n[...
3656ac85-a4ae-44d7-8c52-74f5303e4ff6
public CepFacil(String zipCode, String apiKey) throws IOException, InvalidZipCodeException, AddressNotFoundException { this.zipCode = zipCode; String line, result = ""; try { URL apiUrl = new URL("http://www.cepfacil.com.br/service/?filiacao=" + apiKey + "&cep=" + ...
9c6662d1-6359-402b-a137-9babe7f18bd8
public static String parseZipCode(String zipCode) throws InvalidZipCodeException { /* * This method parses the user informed zip code into a String object that contains * no dashes so the webservice can find it. So, for example, 55555-555 becomes 55555555. * @param zipCode the zipCode...
c1393d64-7259-471e-8b13-7861b154e767
public boolean isValid() { /* * @return true if the informed zip code corresponds to an actual address. Returns false otherwise. */ return this.status.equals("encontrado"); }
87cd6421-a3dc-42ac-a0a0-7460a36ae8a9
public String fullAddress() { /* * Returns the String object for a full description of the address, containing * exactly the address type (street/avenue/lane), street name, neighborhood, city * zip code, state and country name (Brazil only, of course). */ return this....
c6d15173-e21e-4cf7-b987-0ec9568f4888
@Override public String toString() { return this.addressType + " " + this.street + ", " + this.city + " " + this.zipCode + " - " + this.state + ", Brasil"; }
cb0490c7-39ad-4f38-ba90-6098e6852bdb
public String getAPiKey() { return this.apiKey; }
9c998e1f-7058-47e2-a6c4-64dbe643effc
public String getZipCode() { return this.zipCode; }
05e9abb7-16af-4424-9375-74e87655636f
public String getState() { return this.state; }
11e30df9-ac3f-4a22-86a4-377ea4087385
public String getAddressType() { return this.addressType; }
4c3c3e28-a441-421d-a73c-f45314cc99ec
public String getCity() { return this.city; }
7ed89984-bcdd-47cd-a5bc-805662a4c50e
public String getNeighborhood() { return this.neighborhood; }
914f4b2c-b718-42ab-bb4d-fae88bc54c01
public String getStreet() { return this.street; }
dd7a123c-a66e-490b-8955-bd3a93673837
public String getStatus() { return this.status; }
9853f6b4-1fa4-4e22-93f4-244b57069cb1
public AddressNotFoundException() { super("You either informed an invalid API token nonexistent zip code"); }
db8933f8-4fb4-497d-b6e4-26fee04b81cc
public InvalidZipCodeException(String zipCode) { super("The informed zip code is invalid: " + zipCode + ".\n" + "A valid Brazilian zip code contains 8 numeric characters\n"); }
f65c2122-a08b-41bc-a0cd-21721f4713ec
public static void main(String[] args) throws IOException, InvalidZipCodeException, AddressNotFoundException { // zipCode, state, addressType, city, neighborhood, street, status String token = "0E2ACA03-FC7F-4E87-9046-A8C46637BA9D"; CepFacil ruaCasa = new CepFacil("53416-540", token); C...
ed798a0a-f847-4f15-9d67-8971ffd8e670
@Test public void testZipCodeFormat() throws InvalidZipCodeException { String zipCode = "53416-540"; assertEquals("53416540", CepFacil.parseZipCode(zipCode)); }
8f6847f9-af42-4b44-9cc6-dca89f5791aa
public static void main(String[] args) { // TODO Auto-generated method stub RandomGraphGenerator graphGenerator = new RandomGraphGenerator(); //generate graph with 4 vertex and 4 edge RandomGraph graph = graphGenerator.generate(6, 6); MCSTGenerator mcstGenerator = new MCSTGenerator(graph); mcstGenerat...
a0fd4df7-2d90-44c1-a4d6-b92f54f0019e
public Vertex (int name){ this.name = name; }
7b53029f-8089-4bd7-8214-36101173d6e8
public Vertex(){ }
c47aad42-4815-4e2f-8d36-961a5ed46dac
public MCSTGenerator(RandomGraph graph){ this.graph = graph; graph.printGraph(); }
df81876d-4aab-4b9d-8aeb-6905c12b8247
public void prim(){ this.vertexMap = new HashMap<Integer, Vertex>(); priorityQueue = new PriorityQueue<Vertex>(this.graph.vertexList.size(),orderComparator); for (Vertex vertex : this.graph.vertexList) { vertex.key = 100; vertex.parent = null; this.vertexMap.put(vertex.name, vertex); // this.priorit...
8f5416cb-94b2-4d7b-b5e5-ac6cd2749401
private List<Vertex> adjVertex(Vertex v){ int i = v.name; List<Vertex> list = new ArrayList<Vertex>(); for (int j = 0; j < this.graph.vertexList.size(); j++) { if (this.graph.adjMatrix[i][j]>0) { // System.out.println(j); Vertex u = vertexMap.get(j); list.add(u); } } return list; }
50769a7a-1697-45d7-903f-36ef22cad85b
public int compare(Vertex char1 , Vertex char2){ int char1key = char1.key; int char2key = char2.key; if (char1key > char2key) { return 1; }else if (char1key < char2key) { return -1; }else { return 0; } }
e84fa11c-7119-402c-9010-14a2391db14d
public RandomGraph(){ }
94f78739-6918-4118-bb2f-315baa7fdb74
public RandomGraph(List<Vertex>vertexList){ this.vertexList = vertexList; adjMatrix = new int[this.vertexList.size()][this.vertexList.size()]; for (int i = 0; i < vertexList.size(); i++) { for (int j = 0; j < vertexList.size(); j++) { this.adjMatrix[i][j] = 0; } } }
2c2d55c5-c502-449f-9c21-923e97efa8a1
public boolean insertEdge(int i,int j,int w){ if (i != j && this.adjMatrix[i][j] == 0&& this.adjMatrix[j][i] == 0) { this.adjMatrix[i][j] = w; this.adjMatrix[j][i] = w; return true; }else { return false; } }
82857e09-691d-4b01-8bea-fe91c4206f9c
public void printGraph(){ for (int i = 0; i < vertexList.size(); i++) { for (int j = 0; j < vertexList.size(); j++) { System.out.print(this.adjMatrix[i][j]+" "); } System.out.println(); } }
8562c4ea-8c68-458f-8e5f-d7ac59e60e88
public RandomGraphGenerator(){ }
b025c188-d63c-4192-bdec-70634eed961f
public RandomGraph generate(int numOfVertex,int numOfEdge){ if (numOfEdge < numOfVertex-1 || numOfEdge> (numOfVertex*(numOfVertex-1))/2) { System.out.println("The number of edge cannot construct a connected graph "); return null; } for (int i = 0; i < numOfVertex; i++) { Vertex vertex = new Vertex(i); //...
8cf0fc2d-6e40-4e27-9459-cf22af7933a4
public Map<Character, String> getNodeTable() { return nodeTable; }
ad7b5b48-61eb-4b4b-8cd3-a46f2623a3ec
public void setNodeTable(Map<Character, String> nodeTable) { this.nodeTable = nodeTable; }
89bbeed0-9688-451e-88e0-37f94b497142
public void put(Character character,String string){ this.nodeTable.put(character, string); }
5b89354b-e6b1-4ced-996c-38326aea6622
public void binaryDigit(String binary) { this.binary += binary; }
2e61f5cf-c1c1-4c3f-8230-83baba0b5ebf
public Node getRootNode() { return rootNode; }
6e4ef2ba-c300-495a-a419-744926f0bd37
public void setRootNode(Node rootNode) { this.rootNode = rootNode; }
01ff13da-1949-41e2-bd31-49c6248b2a22
public String getOutputString() { return outputString; }
1691d839-35e9-4458-b1ac-e2cac84348e4
public void setOutputString(String outputString) { this.outputString = outputString; }
93a66aa7-7ba1-4b30-aa0e-032c61a0ff3a
public String getInputString() { return inputString; }
04571b3c-276e-4b74-b8c0-b831cfc1e31d
public void setInputString(String inputString) { this.inputString = inputString; }
cacfe94a-eb05-40b5-ab93-39eb1a009a7a
public HuffmanEncode(String string){ //replace space // String string = inputString.replaceAll(" ", ""); // System.out.println(string); this.inputString = string; HashMap<Character, Integer> strhashMap = new HashMap<Character, Integer>(); int num = 0; int count = 0; //pick up a char to compute its ...
fb32f445-8d1b-43f2-86f9-7f0e4def59c5
public void Encoding(){ System.out.println("size is "+priorityQueue.size()); //construct the Huffman tree while (priorityQueue.size()>1) { Node node = new Node(); Node x = new Node(); Node y = new Node(); node.left = x = priorityQueue.poll(); node.right = y = priorityQueue.poll(); node.freque...
7ef054f5-9ff4-4770-b2c1-77362c0f9741
public PriorityQueue(){ this.list = new ArrayList<Node>(); //we do not want to use the first place Node placeHolder = new Node(); //---------------------------test------------------------------- // Node node1 = new Node(); // node1.frequency =1; // node1.name = 'a'; // Node node2 = new Node(); // nod...
753e1968-6421-4a09-8233-ea56234d943b
private void buildMinHeap(List<Node> list){ // this.heapSize = this.list.size(); for (int i = (int)(Math.floor(list.size()/2)); i>=1; i--) { this.minHeapify(list, i); } }
477a6f61-790d-48b8-9327-c8ef02fce206
private void minHeapify(List<Node> list,int i){ int smallest = 0; int l = left(i); int r = right(i); //find the minimum element if (l<= this.list.size()-1 && this.list.get(l).frequency<this.list.get(i).frequency) { smallest = l; }else { smallest = i; } if (r<=this.list.size()-1 && this.list.get(r)...
2bace030-f581-4730-b339-814f9af5b82b
private int left(int i){ return 2*i; }
a8d9f77b-230b-4a0b-845c-8f5920c2bd1b
private int right(int i){ return 2*i+1; }
6c940a5c-2a5c-4cd0-ba9a-1fe0c3690cc3
public Node poll(){ Node minNode = new Node(); if (list.size()<=1) { System.out.println("The priority is empty!"); return minNode; } minNode = this.list.get(1); this.list.set(1, this.list.get(this.list.size()-1)); this.list.remove(this.list.size()-1); this.minHeapify(this.list, 1); return minNode...
960247e2-60aa-497f-b936-10bcbb2d4c4b
public boolean offer(Node node){ this.list.add(node); this.buildMinHeap(this.list); return true; }
459a5dc2-f468-42f0-b105-df391e317b4a
public int size(){ return this.list.size()-1; }
04b24cab-86cc-448c-af4f-be881ae480fe
public NodeTable getNodeTable() { return nodeTable; }
201a2a96-51b3-4db7-9d3b-b745f3935d81
public void setNodeTable(NodeTable nodeTable) { this.nodeTable = nodeTable; }
e256656c-1cc3-4a2f-8624-1855a981bc53
public Node getRoot() { return root; }
c64c0789-058c-4e1c-b9b0-403ea9e18766
public void setRoot(Node root) { this.root = root; }
4c5cbdc3-f8e7-47f8-9cb5-576c1443ce27
public void printTree(Node node){ if (node.left != null && node.right != null) { printTree(node.left); printTree(node.right); }else { nodeTable.put(node.name, node.binary); output += node.name +" = "+ node.binary + " , "; } }
a25579cc-bcb4-46da-b1b3-ceec400f0b32
public void setBinaryTreeArray(Node node){ if (node.left != null) { Node nodeLeft = node.left; nodeLeft.binaryDigit(node.binary+"0"); setBinaryTreeArray(nodeLeft); } if (node.right != null) { Node nodeRight = node.right; nodeRight.binaryDigit(node.binary+"1"); setBinaryTreeArray(nodeRight); } ...
6ac8255d-342e-4e75-8340-36b728309b28
public void write(){ System.out.println("The Huffman tree is "); System.out.println(output); }
42f9bfcd-dda4-4325-885f-458a80406789
public static void main(String[] args){ String content = null; try { //--------------------test---------------------------- File huffmanFile = new File("C:\\Users\\Administrator\\temp\\Huffman.txt"); String encodString = "GBK"; if (huffmanFile.isFile()&&huffmanFile.exists()) { InputStreamRea...
8f1c6d0b-50f0-4172-a838-b3b0cca121c3
public String getHuffmanString() { return huffmanString; }
2ee7d36f-2641-4575-bcde-e82123cb081a
public void setHuffmanString(String huffmanString) { this.huffmanString = huffmanString; }
e3acb2bb-5579-4c49-865d-55ecf6dbb09d
public HuffmanDecode(String string,Node root){ this.huffmanString = string; this.root = root; }
84aa1e9c-6b1d-408f-b7a6-e092470e5655
public void decoding(){ Node currentNode = this.root; for (int i = 0; i < this.huffmanString.length(); i++) { char c = this.huffmanString.charAt(i); //find the leaf if (c == '0') { currentNode = currentNode.left; }else { currentNode = currentNode.right; } //decoding if cur...
4a5f9cf2-88da-4565-ab26-db484a3d53a2
private void printOriginalString(){ System.out.println("This original string is :"); System.out.println(this.originalString); }
bfb6924e-a892-427a-9b17-f8e33e9b97e6
public MyFormat() { super("Adjust your settings"); panel.setLayout(new MigLayout()); panel.add(bridgeSet = new JLabel("Bridge settings:"), "wrap"); panel.add(spacer = new JLabel(" "),"span, grow"); panel.add(numberBars, "span, grow"); panel.add(numOfBars = new JLabel("Num...
d2d2781f-9145-4c8b-9094-6238e8ed0244
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { MyFormat mf = new MyFormat(); mf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); mf.pack(); mf.setLocationByPlatform(true); ...
cb203a69-ac4b-4ff9-8c0a-3d9a9503bd11
public void run() { MyFormat mf = new MyFormat(); mf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); mf.pack(); mf.setLocationByPlatform(true); mf.setVisible(true); }
20fe9b0c-2210-4048-94fb-bc683d165770
public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("*** damn ***"); for(int i=0; i<5; i++){ System.out.println("*** print this value: " + i + " ***"); } try{ } catch(Exception e){ System.err.println(""); } error1(); System.out.println("*** tes...
647b1f1f-a45e-4226-bfd6-f30d89b0d87d
public static void error1(){ System.err.println("error 1"); }
50fb5cdb-0211-4065-b669-e5262cfe8090
public static void error2(){ System.err.println("error 2"); }
ab399649-d6c6-4d8a-90d4-629e436eafa0
public static void error3(){ System.err.println("error 3"); }
aa55b0b1-bc56-4ceb-bc9d-c58fb8b9026f
public static void main(String[] args) { System.out.println("*** sending values from: Param001"); Param002.receive(Param002.createNewIssueCase); Param002.receive(Param002.createLink); Param002.receive(Param002.addressNewLink); System.out.println("*** after sending printing all values ***"); }