mirror of
https://github.com/Xevion/contest.git
synced 2025-12-18 14:11:35 -06:00
rename aplus october 2013
This commit is contained in:
6
uil/aplus-octoboer-2013/10/10/.classpath
Normal file
6
uil/aplus-octoboer-2013/10/10/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
uil/aplus-octoboer-2013/10/10/.project
Normal file
17
uil/aplus-octoboer-2013/10/10/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<projectDescription>
|
||||
<name>10</name>
|
||||
<comment/>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
11
uil/aplus-octoboer-2013/10/10/.vscode/launch.json
vendored
Normal file
11
uil/aplus-octoboer-2013/10/10/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "CodeLens (Launch) - problem10",
|
||||
"request": "launch",
|
||||
"mainClass": "problem10",
|
||||
"projectName": "10"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
uil/aplus-octoboer-2013/10/10/bin/Synonym.class
Normal file
BIN
uil/aplus-octoboer-2013/10/10/bin/Synonym.class
Normal file
Binary file not shown.
BIN
uil/aplus-octoboer-2013/10/10/bin/SynonymOrganizer.class
Normal file
BIN
uil/aplus-octoboer-2013/10/10/bin/SynonymOrganizer.class
Normal file
Binary file not shown.
BIN
uil/aplus-octoboer-2013/10/10/bin/problem10.class
Normal file
BIN
uil/aplus-octoboer-2013/10/10/bin/problem10.class
Normal file
Binary file not shown.
10
uil/aplus-octoboer-2013/10/10/input.dat
Normal file
10
uil/aplus-octoboer-2013/10/10/input.dat
Normal file
@@ -0,0 +1,10 @@
|
||||
4
|
||||
this paragraph was fun to write i love to write fun assignments
|
||||
having work to do is very fun my favorite subject is english but
|
||||
i also love to write programs which is a close second but not
|
||||
bad this bad assignment was bad bad bad bad and bad
|
||||
4
|
||||
fun diverting festive
|
||||
love enjoy relish
|
||||
write scribe code
|
||||
bad horrible bitter terrible evil base rancid
|
||||
94
uil/aplus-octoboer-2013/10/10/src/problem10.java
Normal file
94
uil/aplus-octoboer-2013/10/10/src/problem10.java
Normal file
@@ -0,0 +1,94 @@
|
||||
import static java.lang.System.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
class Synonym {
|
||||
int index = 0;
|
||||
List<String> synonyms;
|
||||
Synonym(String[] synonyms) {
|
||||
this.synonyms = Arrays.asList(synonyms);
|
||||
}
|
||||
|
||||
String next() {
|
||||
return synonyms.get(this.index++ % synonyms.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SynonymOrganizer {
|
||||
Map<String, Integer> points = new HashMap<String, Integer>();
|
||||
List<Synonym> synonyms = new ArrayList<Synonym>();
|
||||
|
||||
// Takes lines of synonyms
|
||||
SynonymOrganizer(String[] synlines) {
|
||||
int creationIndex = 0;
|
||||
// Iterate over each line and process synonyms
|
||||
for(String line : synlines) {
|
||||
// Get all words in synonym list
|
||||
String[] words = line.split("\\s");
|
||||
for(String word : words) {
|
||||
// Can switch off to using Map<String, ArrayList<Integer>> for multi-value synonyms instead of singular
|
||||
if(points.containsKey(word))
|
||||
out.println("Word \"" + word + "\" already used for previous synonym, overwriting.");
|
||||
points.put(word, creationIndex);
|
||||
}
|
||||
// Add the list of synonyms with new Synonym object
|
||||
synonyms.add(new Synonym(words));
|
||||
// Increment for next pointer
|
||||
creationIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasSynonym(String word) {
|
||||
return points.containsKey(word);
|
||||
}
|
||||
|
||||
// Gets a synonym, increments synonym object index
|
||||
String getSynonym(String word) {
|
||||
// Pointless in a perfect world
|
||||
if(!points.containsKey(word)) {
|
||||
out.println("Word\"" + word + "\"had no synonyms!");
|
||||
}
|
||||
// Retriever integer map pointer, then return next synonym
|
||||
int pointer = points.get(word);
|
||||
return synonyms.get(pointer).next();
|
||||
}
|
||||
}
|
||||
|
||||
public class problem10 {
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
// Initial Constants
|
||||
File input = new File("input.dat");
|
||||
Scanner read = new Scanner(input);
|
||||
|
||||
// Read paragraph lines
|
||||
String[] rawParagraph = new String[Integer.parseInt(read.nextLine())];
|
||||
for(int i = 0; i < rawParagraph.length; i++)
|
||||
rawParagraph[i] = read.nextLine();
|
||||
|
||||
// Read synonym lines
|
||||
String[] synonymLines = new String[Integer.parseInt(read.nextLine())];
|
||||
for(int i = 0; i < synonymLines.length; i++)
|
||||
synonymLines[i] = read.nextLine();
|
||||
|
||||
// Start processing the paragraph
|
||||
SynonymOrganizer organizer = new SynonymOrganizer(synonymLines);
|
||||
for(String line : rawParagraph) {
|
||||
String[] words = line.split("\\s");
|
||||
for(int i = 0; i < words.length; i++) {
|
||||
// Replace if organizer has a synonym
|
||||
if(organizer.hasSynonym(words[i])) {
|
||||
words[i] = organizer.getSynonym(words[i]);
|
||||
}
|
||||
}
|
||||
out.println(String.join(" ", words));
|
||||
}
|
||||
read.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user