Answer to Question #290961 in C for Savita

Question #290961

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 or 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.


Input Specification:


input1: S, string of digits


input2: Y, No number should be greater than Y


input3: Size of the String S


Output Specification:


Your function should return M, the minimum number of sets


Example 1:


input1: "1234"​

1
Expert's answer
2022-01-26T17:48:44-0500
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;


void Subsets(int *arr, int i, int n,int *subset, int j)
{    
    if(i==n)
	{
        int idx = 0;
        while(idx<j){
            printf("%d, ",subset[idx]);//])cout<<subset[idx]<<' ';
            ++idx;
        }
        printf("\n");//cout<<endl;
        return;
    }
    Subsets(arr,i+1,n,subset,j);
    subset[j] = arr[i];
    Subsets(arr,i+1,n,subset,j+1);
}
int main()
{
    int arr[] = {1,2,3,4}; // input array
    int subset[100];       // temporary array to store subset
    int n = 4;
    Subsets(arr,0,n,subset,0);   
}

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