Skip to content

Instantly share code, notes, and snippets.

@Zulcom
Created April 25, 2015 18:12
Show Gist options
  • Save Zulcom/6e7571df3dce0d018fb2 to your computer and use it in GitHub Desktop.
Save Zulcom/6e7571df3dce0d018fb2 to your computer and use it in GitHub Desktop.
Требуется написать программу, которая определяет, есть ли во входной последовательности цифры и выводит наиболльшее число, которое можно составить из этих цифр
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