Created
April 25, 2015 18:12
-
-
Save Zulcom/6e7571df3dce0d018fb2 to your computer and use it in GitHub Desktop.
Требуется написать программу, которая определяет, есть ли во входной последовательности цифры и выводит наиболльшее число, которое можно составить из этих цифр
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class c4_5{ | |
public static void main(String[] args){ | |
String s = new Scanner(System.in).nextLine().replaceAll("[^0-9]+", ""); | |
if(s.length() == 0) System.out.println("No"); | |
else{ | |
ArrayList<Character> digits = new ArrayList<>(); | |
for(Character c : s.toCharArray()) digits.add(c); | |
Collections.sort(digits, Collections.reverseOrder()); | |
System.out.println("Yes"); digits.forEach(System.out::print); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment