problem 7 finish

This commit is contained in:
Xevion
2019-09-17 01:59:55 -05:00
parent 8d24ff3a08
commit 0b37e5e1fc
3 changed files with 49 additions and 47 deletions

View File

@@ -2,10 +2,7 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="bb180874-2412-4c96-b84b-4eb63b971832" name="Default Changelist" comment=""> <list default="true" id="bb180874-2412-4c96-b84b-4eb63b971832" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/problem7.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/problem7.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/input.dat" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/problem7.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../6/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../6/.idea/workspace.xml" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -24,25 +21,25 @@
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.extensions.open"> <usages-collector id="statistics.file.extensions.open">
<counts> <counts>
<entry key="dat" value="1" /> <entry key="dat" value="2" />
<entry key="java" value="1" /> <entry key="java" value="1" />
</counts> </counts>
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.types.open"> <usages-collector id="statistics.file.types.open">
<counts> <counts>
<entry key="JAVA" value="1" /> <entry key="JAVA" value="1" />
<entry key="PLAIN_TEXT" value="1" /> <entry key="PLAIN_TEXT" value="2" />
</counts> </counts>
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.extensions.edit"> <usages-collector id="statistics.file.extensions.edit">
<counts> <counts>
<entry key="dat" value="532" /> <entry key="dat" value="532" />
<entry key="java" value="1745" /> <entry key="java" value="3129" />
</counts> </counts>
</usages-collector> </usages-collector>
<usages-collector id="statistics.file.types.edit"> <usages-collector id="statistics.file.types.edit">
<counts> <counts>
<entry key="JAVA" value="1745" /> <entry key="JAVA" value="3129" />
<entry key="PLAIN_TEXT" value="532" /> <entry key="PLAIN_TEXT" value="532" />
</counts> </counts>
</usages-collector> </usages-collector>
@@ -53,8 +50,8 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/problem7.java"> <entry file="file://$PROJECT_DIR$/src/problem7.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="356"> <state relative-caret-position="424">
<caret line="29" lean-forward="true" selection-start-line="29" selection-end-line="29" /> <caret line="51" selection-start-line="51" selection-end-line="51" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>
@@ -65,8 +62,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/input.dat"> <entry file="file://$PROJECT_DIR$/input.dat">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255"> <state relative-caret-position="102">
<caret line="15" column="17" selection-start-line="15" selection-start-column="9" selection-end-line="15" selection-end-column="17" /> <caret line="6" column="29" lean-forward="true" selection-start-line="6" selection-start-column="29" selection-end-line="6" selection-end-column="29" />
</state> </state>
</provider> </provider>
</entry> </entry>
@@ -80,6 +77,11 @@
</list> </list>
</option> </option>
</component> </component>
<component name="FindInProjectRecents">
<findStrings>
<find>tortillas</find>
</findStrings>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." />
</component> </component>
@@ -128,7 +130,7 @@
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568702269577" /> <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568703586398" />
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
@@ -207,15 +209,15 @@
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/input.dat"> <entry file="file://$PROJECT_DIR$/input.dat">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255"> <state relative-caret-position="102">
<caret line="15" column="17" selection-start-line="15" selection-start-column="9" selection-end-line="15" selection-end-column="17" /> <caret line="6" column="29" lean-forward="true" selection-start-line="6" selection-start-column="29" selection-end-line="6" selection-end-column="29" />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/problem7.java"> <entry file="file://$PROJECT_DIR$/src/problem7.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="356"> <state relative-caret-position="424">
<caret line="29" lean-forward="true" selection-start-line="29" selection-end-line="29" /> <caret line="51" selection-start-line="51" selection-end-line="51" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>

View File

Binary file not shown.

View File

@@ -2,6 +2,7 @@ import static java.lang.System.*;
import java.util.Arrays; import java.util.Arrays;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner; import java.util.Scanner;
public class problem7 { public class problem7 {
@@ -16,39 +17,38 @@ public class problem7 {
for(int i = 0; i < lines; i++) { for(int i = 0; i < lines; i++) {
// Process all lines into primitive String arrays // Process all lines into primitive String arrays
int listLines = read.nextInt(); int listLines = read.nextInt();
read.nextLine();
String rawGroceryList = ""; String rawGroceryList = "";
String rawReceiptList = ""; String rawReceiptList = "";
for(int x = 0; x < listLines; x++) rawGroceryList += read.nextLine(); read.nextLine();
for(int x = 0; x < listLines; x++) rawReceiptList += read.nextLine(); // Process all lines into words
String[] groceryList = rawGroceryList.split("\\s"); for(int x = 0; x < listLines; x++)
String[] receiptList = rawReceiptList.split("\\s"); rawGroceryList += read.nextLine() + "\n";
out.println(Arrays.toString(groceryList)); for(int x = 0; x < listLines; x++)
out.println(Arrays.toString(receiptList)); 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+"));
// Processes all words in // Find which to put back
static String[] processWords(String[] lines) { String putBack = "PUT BACK";
int length = 0; for(String item : receiptList) {
// Count how long the final array should be if(groceryList.indexOf(item) == -1)
for (String line : lines) { putBack += " " + item;
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++;
} }
// 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;
} }
} }