Skip to content
Snippets Groups Projects
Commit ba612f8f authored by DerechteDani's avatar DerechteDani
Browse files

nix

parent bd739dbc
Branches master
No related tags found
No related merge requests found
......@@ -11,3 +11,5 @@
/synchro/
>>>>>>> branch 'master' of https://git.htltraun.at/T90016/5bhit.git
/phonebook/
/level1/
/ccc/
package ccc;
import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class lvl1 {
public static void main(String[] args) {
try {
String filename = "C:\\Users\\walle\\Downloads\\level2\\level2_1.";
List<String> in = Files.readAllLines(Paths.get(filename + "in"));
// Extracting input data from the list
int N = Integer.parseInt(in.get(0)); // Number of currencies
int lineIndex = 1; // Current index in the input list
StringBuilder outputBuilder = new StringBuilder(); // For storing output
for (int i = 0; i < N; i++) {
int C = Integer.parseInt(in.get(lineIndex++)); // Number of coin values per currency
int A = Integer.parseInt(in.get(lineIndex++)); // Number of amounts per currency
for (int j = 0; j < A; j++) {
String[] currencyValuesStr = in.get(lineIndex++).split(" ");
int[] currencyValues = new int[C];
for (int k = 0; k < C; k++) {
currencyValues[k] = Integer.parseInt(currencyValuesStr[k]); // Parse currency values
}
int amount = Integer.parseInt(in.get(lineIndex++)); // Amount to construct
// Find a pair of values that sum up to the amount
int value1 = -1, value2 = -1;
for (int m = 0; m < C; m++) {
for (int n = m; n < C; n++) {
if (currencyValues[m] + currencyValues[n] == amount) {
value1 = currencyValues[m];
value2 = currencyValues[n];
break;
}
}
if (value1 != -1 && value2 != -1) {
break;
}
}
// Append the pair to the output
outputBuilder.append(value1).append(" ").append(value2).append("\n");
}
}
// Writing output to file
File myObj = new File(filename + "out");
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
} else {
System.out.println("File already exists.");
}
FileWriter myWriter = new FileWriter(filename + "out");
myWriter.write(outputBuilder.toString()); // Write the output to file
myWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment