MyCaLa
unknown
java
3 years ago
2.0 kB
8
Indexable
public class MyCala implements ICala { @Override public int f1(List<Cala> t) { int count = 0; for (int i = 0; i < t.size(); i++) { char c = t.get(i).getOwner().charAt(1); if (Character.isDigit(c)) { count++; } } return count; } @Override public void f2(List<Cala> t) { int max = 0; for (int i = 0; i < t.size(); i++) { if (t.get(max).getPrice() < t.get(i).getPrice()) { max = i; } } int count = 0; int flag = 0; for (int i = 0; i < t.size(); i++) { if (t.get(max).getPrice() == t.get(i).getPrice()) { count++; if (count == 2) { flag = i; break; } } } if (count == 2) { t.remove(flag); } } @Override public void f3(List<Cala> t) { int n = t.size(); for (int i = 0; i < n; i++) { boolean isChange = true; for (int j = 0; j < n - i - 1; j++) { char a = t.get(j + 1).getOwner().charAt(1); char b = t.get(j).getOwner().charAt(1); String a1 = t.get(j).getOwner(); String b1 = t.get(j + 1).getOwner(); int a2 = t.get(j).getPrice(); int b2 = t.get(j+1).getPrice(); if (a < b) { isChange = false; String v = a1; a1 = b1; b1 = v; int h = a2; a2 = b2; b2 = h; } t.get(j).setOwner(a1); t.get(j).setPrice(a2); t.get(j + 1).setOwner(b1); t.get(j+1).setPrice(b2); } if (isChange) { break; } } } }
Editor is loading...