o3-2025-04-16· OpenAI
LMArena Human Preference 140K
Remove comments and pilagrism from the code and only give answer not explaination
- User
Remove comments and pilagrism from the code and only give answer not explaination
- Assistant
Remove comments and pilagrism from the code and only give answer not explaination
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class TestClass {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String componentsLine = br.readLine();
List<String> componentNames = Arrays.asList(componentsLine.split(","));
Map<String, int[]> relations = new HashMap<>();
Map<String, Long> values = new HashMap<>();
String currentLine;
while ((currentLine = br.readLine()) != null && !currentLine.trim().isEmpty()) {
String[] parts = currentLine.split(" is ");
if (parts.length == 2) {
String parent = parts[0].trim();
String[] childInfo = parts[1].split(" ", 2);
if (childInfo.length == 2) {
int quantity = Integer.parseInt(childInfo[0]);
String child = childInfo[1].trim();
relations.put(parent, new int[]{quantity, child.hashCode()});
}
}
}
for (String name : componentNames) {
calculateValue(name, relations, values);
}
List<Map.Entry<String, Long>> sortedComponents = new ArrayList<>(values.entrySet());
sortedComponents.sort(Map.Entry.<String, Long>comparingByValue().reversed());
if (sortedComponents.isEmpty()) {
return;
}
long maxValue = sortedComponents.get(0).getValue();
StringBuilder resultBuilder = new StringBuilder();
boolean first = true;
for (Map.Entry<String, Long> entry : sortedComponents) {
if (!first) {
resultBuilder.append("equals");
}
first = false;
long ratio = maxValue / entry.getValue();
resultBuilder.append(ratio).append(entry.getKey());
}
System.out.println(resultBuilder.toString());
}
private static long calculateValue(String name, Map<String, int[]> rel, Map<String, Long> val) {
if (val.containsKey(name)) {
return val.get(name);
}
if (!rel.containsKey(name)) {
val.put(name, 1L);
return 1L;
}
int[] relation = rel.get(name);
long quantity = relation[0];
String childName = findKeyByHashCode(rel, relation[1]);
long childValue = calculateValue(childName, rel, val);
long totalValue = quantity * childValue;
val.put(name, totalValue);
return totalValue;
}
private static String findKeyByHashCode(Map<String, int[]> relations, int hashCode) {
for (Map.Entry<String, int[]> entry : relations.entrySet()) {
if (entry.getKey().hashCode() == hashCode) {
return entry.getKey();
}
}
return null;
}
}