ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Password Modifier

Strengthen a password by swapping some letters for symbols and adding its length at the end.

สิ่งที่คุณจะได้เรียนรู้

  • Walk through a string one character at a time
  • Map characters to replacements
  • Append a number converted to text

โจทย์

ดูฉบับแปล

A school IT club suggests a quick way to turn a simple word into a stronger password. Swap these lowercase letters for look-alike symbols:

LetterBecomes
a@
e3
i!
o0 (zero)
s$

Every other character stays as it is (capital letters are not swapped). Then add # and the length of the original word at the end.

Implement password_modifier(word).

Input

word: The starting word.

Output

Return the new password.

เงื่อนไข

0 ≤ length of word ≤ 100

word uses printable ASCII characters

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
word = "mississippi"

ผลลัพธ์ที่คาดหวัง:
expected = "m!$$!$$!pp!#11"
อินพุต:
std::string word = "mississippi";

ผลลัพธ์ที่คาดหวัง:
std::string expected = "m!$$!$$!pp!#11";
อินพุต:
string word = "mississippi";

ผลลัพธ์ที่คาดหวัง:
string expected = "m!$$!$$!pp!#11";

คำอธิบาย

Every i becomes ! and every s becomes $, and the word has 11 letters: "m!$$!$$!pp!#11".

ตัวอย่างที่ 2
อินพุต:
word = "Oreo"

ผลลัพธ์ที่คาดหวัง:
expected = "Or30#4"
อินพุต:
std::string word = "Oreo";

ผลลัพธ์ที่คาดหวัง:
std::string expected = "Or30#4";
อินพุต:
string word = "Oreo";

ผลลัพธ์ที่คาดหวัง:
string expected = "Or30#4";

คำอธิบาย

The capital O stays, e becomes 3 and the last o becomes 0; the length is 4: "Or30#4".

แนวทางการแก้

ลองทำเองก่อน แล้วค่อยเปิดคำใบ้ทีละข้อ

คำใบ้ 1

Look at each character and decide what to write in its place.

คำใบ้ 2

Only the five lowercase letters change; everything else is copied.

คำใบ้ 3

Use the length of the original word, then convert it to text before adding it.

ความซับซ้อนที่คาดหวัง

O(n) time, O(n) extra space

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

คำตอบที่ผ่านดีที่สุดของแต่ละคน คำตอบที่เร็วกว่า ใช้หน่วยความจำน้อยกว่า และได้คะแนนดีกว่าจะอยู่ด้านบน

ยังไม่มีคำตอบที่ผ่าน แก้โจทย์นี้แล้วคว้าอันดับหนึ่งไปเลย

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก