// Java program to implement the above approach
import java.io.*;
import java.lang.*;
import java.util.*;
class GFG{
// Function to construct the original set of digits
// from the string in ascending order
static String construct_digits(String s)
{
// Store the unique characters
// corresponding to word and number
char[] k = { 'z', 'w', 'u', 'x', 'g',
'h', 'o', 'f', 'v', 'i' };
String[] l = { "zero", "two", "four", "six", "eight",
"three", "one", "five", "seven", "nine" };
int[] c = { 0, 2, 4, 6, 8, 3, 1, 5, 7, 9 };
// Store the required result
List<Integer> ans = new ArrayList<>();
// Store the frequency of
// each character of S
HashMap<Character, Integer> d = new HashMap<>();
for(int i = 0; i < s.length(); i++)
{
d.put(s.charAt(i),
d.getOrDefault(s.charAt(i), 0) + 1);
}
// Traverse the unique characters
for(int i = 0; i < k.length; i++)
{
// Store the count of k[i] in S
int x = 0;
if (d.containsKey(k[i]))
x = d.get(k[i]);
// Traverse the corresponding word
for(int j = 0; j < l[i].length(); j++)
{
// Decrement the frequency
// of characters by x
if (d.containsKey(l[i].charAt(j)))
d.put(l[i].charAt(j),
d.get(l[i].charAt(j)) - x);
}
// Append the digit x times to ans
for(int j = 0; j < x; j++)
ans.add(c[i]);
}
// Sort the digits in ascending order
Collections.sort(ans);
String str = "";
for(int val : ans)
str += val;
return str;
}
// Driver Code
public static void main(String[] args)
{
// Given string, s
String s = "fviefuro";
// Function Call
System.out.println(construct_digits(s));
}
}
// This code is contributed by Kingash