Skip to content

Latest commit

 

History

History
18 lines (18 loc) · 858 Bytes

File metadata and controls

18 lines (18 loc) · 858 Bytes

เราสามารถเก็บมุกทั้งหมดที่อ้วนเล่นในอะเรย์ของสตริง โดยรวมมุกซ้ำไปด้วย จากนั้นเราจะเรียงมุกทั้งหมดตามลำดับตัวอักษร และตัดมุกที่ซ้ำทิ้ง ซึ่งสามารถใช้ library ใน STL เช่น

  sort(note.begin(), note.end());
  note.resize(unique(note.begin(), note.end()) - note.begin());
  for (auto s: note) cout << s << "\n";
}

หรือเขียนเช็คมุกซ้ำเองเช่น

  sort(note.begin(), note.end());
  string last = "";
  for (auto s: note) {
    if (s == last) continue;
    last = s;
    cout << s << "\n";
  }
}