cswork / OA打开练习工作台

GreyOrangeOA #1

Roman Numerals in Strings

估计简单评测数据准备中,可先阅读题面

考点(AI 标注)字符串原地数组

You are given a string that contains a name followed by Roman numerals. Your task is to return a vector of strings that stores:

    1. The string name.
    1. The numerical value of the Roman numeral (converted to integer). The names should be in ascending order, and if the names are the same, the numbers should also be sorted in ascending order. Input Format:
  • A list of strings where each string is in the format: name RomanNumeral. Output: Return a vector of strings, sorted by name and numeral value. Notes:
  • The Roman numeral, when converted to a number, is at most two digits.

Example 1

Input:

strings = ["John IX", "Mary XV", "John VIII", "Mary IX"]

Output:

["John 8", "John 9", "Mary 9", "Mary 15"]

Explanation: The names and their corresponding Roman numerals are sorted in ascending order. The Roman numerals are converted to integers as follows:

  • IX -> 9
  • XV -> 15
  • VIII -> 8
  • IX -> 9 The sorted output is: ["John 8", "John 9", "Mary 9", "Mary 15"].