Skip to content

Files

This branch is up to date with matthewsamuel95/ACM-ICPC-Algorithms:master.

largest_number_divisible_by_three

Problem Description

Given a non-negative number up to 10 digits long, find the largest number that can be formed with the digits and is divisible by 3. If no number can be formed that is divisible by 3, return 0.

Input: int Output int

Examples:

  • largest_div_by_three(0) -> 0
  • largest_div_by_three(24) -> 42
  • largest_div_by_three(319) -> 93
  • largest_div_by_three(113) -> 3
  • largest_div_by_three(111) -> 111