Answer to Question #223741 in Java | JSP | JSF for Khushbu

Question #223741
Wedding game

In a wedding that you are attending, there are some chairs that have digits inscribed at their
backs. The chairs are lined in a row such that they form a string of the digits. Find the
minimum number of sets M that can be formed from these digits such that:
1. The number of digits in each set is one gf more than one.
2. Each set is formed using consecutive digits and no digit can be used more than once.
3. In each set, the number formed using the digits is less than or equal to Y.​
1
Expert's answer
2021-08-06T04:25:37-0400
import java.util.*;
 
class Main
{
static int M_S(String s, int x)
{
    int count = 0;
    int n = 0;
 
    int l = s.length();
    boolean f = false;
    for (int i = 0; i < l; i++) {
        n = n * 10 + (s.charAt(i) - '0');
        if (n <= x)
            f = true;
        else 
        {
            if (f)
                count += 1;
            n = s.charAt(i) - '0';
            f = false;
            if (n <= x)
                f = true;
            else
                n = 0;
        }
    }
 
    if (f == true)
        count += 1;
 
    return count;
}
 


public static void main(String args[])
{
    String s;
    Scanner in=new Scanner(System.in);
    s=in.next();
    int x = 30;
    System.out.println(M_S(s, x));
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS