[AtCoder] ABC 128 B – Guidebook
問題
方針
複数の順序があるデータに対する整列は、独自クラスを作成し、順序を定義すると標準ライブラリでソートができます。
コード
提出したコード
構造体に順序を持たせる (C++)
struct Rest { int id, point; string city; Rest(int id, string city, int point) : id(id), point(point), city(city){} bool operator< (const Rest& rest) const { if (rest.city == city) { return rest.point < point; } else { return city < rest.city; } } };
クラスに順序を持たせる (Python)
class Rest: def __init__(self, idx, city, point): self.idx = idx self.city = city self.point = point def __repr__(self): return repr((self.idx, self.city, self.point)) def __lt__(self, other): if self.city == other.city: return self.point > other.point else: return self.city < other.city
ディスカッション
コメント一覧
まだ、コメントがありません