diff --git a/md/0038.md b/md/0038.md new file mode 100644 index 0000000..7579a94 --- /dev/null +++ b/md/0038.md @@ -0,0 +1,18 @@ +เราสามารถเก็บมุกทั้งหมดที่อ้วนเล่นในอะเรย์ของสตริง โดยรวมมุกซ้ำไปด้วย จากนั้นเราจะเรียงมุกทั้งหมดตามลำดับตัวอักษร และตัดมุกที่ซ้ำทิ้ง ซึ่งสามารถใช้ library ใน STL เช่น +```cpp + sort(note.begin(), note.end()); + note.resize(unique(note.begin(), note.end()) - note.begin()); + for (auto s: note) cout << s << "\n"; +} +``` +หรือเขียนเช็คมุกซ้ำเองเช่น +```cpp + sort(note.begin(), note.end()); + string last = ""; + for (auto s: note) { + if (s == last) continue; + last = s; + cout << s << "\n"; + } +} +```