Amazon VO 面试真题解析:字符串中所有货币金额统一打85折

14次阅读
没有评论

Write a function that takes in a string and decreases all monetary values in the string by 15%.

Examples:

// "I spent $100.00 on Amazon this week." -> "I spent $85.00 on Amazon this week."
// "This candy costs $1.00" -> "This candy costs $0.85"

这道 Amazon VO 题要求你处理一段文本,把其中所有以美元形式出现的金额统一减少 15%。核心做法通常是用字符串扫描或正则表达式找出形如 <code>$100.00</code> 的货币片段,提取数值后按 0.85 计算,再按原格式替换回去。重点在于正确金额边界、保留原句中的其他字符不变,并注意小数位的格式化输出。

正文完
 0