51. Transforming a list of phone numbers

This problem is somewhat similar in some aspects to the previous one. However, instead of selecting phone numbers that start with a specified country code, we must transform each number so that they all start with that country code preceded by a +. There are several cases that must be considered:

  • The phone number starts with a 0. That indicates a number without a country code. To modify the number to include the country code we must replace the 0 with the actual country code, preceded by +.
  • The phone number starts with the country code. In this case, we just prepend + sign to the beginning.
  • The phone number starts with + followed by the country code. In this case, the number is already in the expected ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.