Štetje števk - Starc Aljaz¶
Author's note
Ta resitev je utterly bad. Ma dela, and I'm happy with it ker imam samo se kaksno urco za oddat in se mi trenutno ne da vlagat vec energije :glad:
Lpa.
Utterly bad solution
import java.util.*;
class DN05 {
public static void main (String[] args) {
Map <Character, Integer> counts = new HashMap<Character, Integer>();
String srcstr = "";
int maxcount = 0;
for (int i = 0; i < args.length; i++) srcstr += args[i];
for (int i = 0; i < srcstr.length(); i++) {
char chr = srcstr.charAt(i);
if (Character.isDigit(chr)) {
int cnt = counts.getOrDefault(chr, 0);
counts.put(chr, cnt + 1);
if (maxcount < cnt + 1) maxcount = cnt + 1;
}
}
if (maxcount != 0) {
System.out.print(" '" + String.join(" ", args) + "' -> ");
for (Map.Entry<Character, Integer> entry : counts.entrySet()) {
if (entry.getValue() == maxcount) System.out.print(entry.getKey() + " ");
}
System.out.println("(" + maxcount + ")");
} else System.out.println("V nizu '" + String.join(" ", args) +"' ni stevk");
}
}
Zadnja posodobitev:
April 5, 2022