mirror of
https://github.com/Xevion/contest.git
synced 2025-12-17 20:11:32 -06:00
problem 7 finish
This commit is contained in:
@@ -2,6 +2,7 @@ import static java.lang.System.*;
|
||||
import java.util.Arrays;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class problem7 {
|
||||
@@ -16,39 +17,38 @@ public class problem7 {
|
||||
for(int i = 0; i < lines; i++) {
|
||||
// Process all lines into primitive String arrays
|
||||
int listLines = read.nextInt();
|
||||
read.nextLine();
|
||||
String rawGroceryList = "";
|
||||
String rawReceiptList = "";
|
||||
for(int x = 0; x < listLines; x++) rawGroceryList += read.nextLine();
|
||||
for(int x = 0; x < listLines; x++) rawReceiptList += read.nextLine();
|
||||
String[] groceryList = rawGroceryList.split("\\s");
|
||||
String[] receiptList = rawReceiptList.split("\\s");
|
||||
out.println(Arrays.toString(groceryList));
|
||||
out.println(Arrays.toString(receiptList));
|
||||
}
|
||||
}
|
||||
|
||||
// Processes all words in
|
||||
static String[] processWords(String[] lines) {
|
||||
int length = 0;
|
||||
// Count how long the final array should be
|
||||
for (String line : lines) {
|
||||
Scanner counter = new Scanner(line);
|
||||
while (counter.hasNext()) {
|
||||
counter.next();
|
||||
length++;
|
||||
}
|
||||
}
|
||||
// Begin inserting into an array
|
||||
String[] output = new String[length];
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
Scanner reader = new Scanner(line);
|
||||
while (reader.hasNext()) {
|
||||
output[i] = reader.next();
|
||||
i++;
|
||||
read.nextLine();
|
||||
// Process all lines into words
|
||||
for(int x = 0; x < listLines; x++)
|
||||
rawGroceryList += read.nextLine() + "\n";
|
||||
for(int x = 0; x < listLines; x++)
|
||||
rawReceiptList += read.nextLine() + "\n";
|
||||
// Split by any whitespace sequence into ArrayLists
|
||||
List<String> groceryList = Arrays.asList(rawGroceryList.split("\\s+"));
|
||||
List<String> receiptList = Arrays.asList(rawReceiptList.split("\\s+"));
|
||||
// Find which to put back
|
||||
String putBack = "PUT BACK";
|
||||
for(String item : receiptList) {
|
||||
if(groceryList.indexOf(item) == -1)
|
||||
putBack += " " + item;
|
||||
}
|
||||
// Find which to buy more of
|
||||
String buyMore = "BUY MORE";
|
||||
for(String item : groceryList) {
|
||||
if(receiptList.indexOf(item) == -1)
|
||||
buyMore += " " + item;
|
||||
}
|
||||
// Process and return final putback/buymore consensus
|
||||
if(putBack.equals("PUT BACK") && buyMore.equals("BUY MORE"))
|
||||
out.println("OK");
|
||||
else if (!putBack.equals("PUT BACK") && buyMore.equals("BUY MORE"))
|
||||
out.println(putBack);
|
||||
else if (putBack.equals("PUT BACK") && !buyMore.equals("BUY MORE"))
|
||||
out.println(buyMore);
|
||||
else
|
||||
out.println(putBack + "\n" + buyMore);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user