Computer Science, asked by punia9211, 7 months ago

Find Password:
Detective Buckshee Junior has been approached by the shantiniketan kids
society for help in finding the password to the games complex. After hearing the
scenario, detective Buckshee Junior realises that he will need a programmer's
support He contacts you and requests your help. Please help the detective by
writing a function to generate the password,
The scenario is as below
Five numbers are available with the kids
These numbers are either stable or unstable
A number is stable if each of its digit occur the same number of times, ie the
frequency of each digit in the number is the same. Foreg 2277 4004. 11. 23
583835, 1010 are examples of stable numbers
Similarly. A number is unstable if the frequency of each digit in the number is
NOT the same. For e.g. 221, 4314. 101, 233, 58135, 101 are examples of
unstable numbers
The password can be found as below
Te password = Maximum of all stable numbers - Minimum of all stable​

Answers

Answered by seelamahit912
4

Complete the function to find and return the password, assuming the five digits are supplied to it as input1, input2, input3, input4, and input5.

If input1 is 12, input2 is 1313, input3 is 122, input4 is 678, and input5 is 898, the table numbers are 12, 1313, and 678.

The numbers 122 and 898 are insecure.

Code:

int[] num = {input1, input2, input3, input4, input5};

int max_unstable=Integer.MIN_VALUE, min_stable=Integer.MAX_VALUE, i, j;

for(i=0;i<5;i++)

{

int[] freq = new int[10];//frequencies of all the digits

int temp=num[i];

int maxf=0;

while(temp!=0)

{

int r = temp%10;

freq[r]++;

temp/=10;

if(freq[r]>maxf)

maxf=freq[r];

}

for(j=0;j<10;j++)

{

if(freq[j]!=0 && freq[j]!=maxf)

break;

}

if(j==10&&num[i]<min_stable)

min_stable=num[i];

else if(j!=10num[i]>max_unstable)

max_unstable=num[i];

}

if(max_unstable==Integer.MIN_VALUE)

max_unstable=0;

if(min_stable==Integer.MAX_VALUE)

min_stable=0;

return (max_unstable + min_stable);

#SPJ2

Answered by aryansuts01
2

Answer:

Concept:

The process of carrying out a specific computation through the design and construction of an executable computer programme is known as computer programming. Analysis, algorithm generation, resource use profiling, and algorithm implementation are some of the duties involved in programming. Instead of being written in machine code, which is immediately executed by the CPU, a programme is written in one or more languages that are understandable to programmers. Finding a set of instructions that will automate a task's completion on a computer is the goal of programming, which is frequently done to solve a specific problem. The application domain, particular algorithms, and formal logic are only a few examples of the many areas of expertise that are often required for competent programming.

Given:

Find Password:

The Shantiniketan Kids Society has contacted Detective Buckshee Junior for assistance in locating the password to the gaming complex. Detective Buckshee Junior realises that he will require a programmer's assistance after hearing the story. He contacts you and asks for your assistance. The scenario is as follows. Would you kindly assist the investigator by creating a method to generate the password? There are five numbers available to the child. These figures either show stability or instability. If each of a number's digits occurs the same number of times, or if the frequency of each digit in the number is the same, then the number is stable. Foreg 2277 4004. 11. 23 583835, 1010 are examples of stable numbers Similarly. If the frequency of each digit in a number is not the same, the number is unstable.For e.g. 221, 4314. 101, 233, 58135, 101 are illogical examples of numbers.

The password can be found as below

The password = Maximum of all stable numbers - Minimum of all stable​

Find:

find the code for the given question

Answer:

import java.io.*;

import java.util.*;

class fiir

{

public static void main(String ar[])

{

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int sum=0;

int inp[]=new int[n];

for(int m=0;m<n;m++)

{

inp[m]=sc.nextInt();

}

int dig[]=new int[10];

int un=0,st=0;

//char c[];

String s=" ";

String sstr="";

String ustr="";

TreeSet<Integer> tr=new TreeSet<Integer>();

for(int i=0;i<inp.length;i++)

{

s=String.valueOf(inp[i]);

char c[]=s.toCharArray();

int narr[]=new int[c.length];

for(int j=0;j<c.length;j++)

{

narr[j]=Integer.parseInt(String.valueOf(c[j]));

}

for( int k=0;k<narr.length;k++)

{

dig[narr[k]]=(dig[narr[k]])+1;

}

for(int p=0;p<10;p++)

{

if(dig[p]!=0)

{

tr.add(dig[p]);

}

}

if(tr.size()>1)

{

un=un+1;

ustr+=s+" ";

}

else

{

st=st+1;

sstr+=s+" ";

}

for(int o=0;o<10;o++)

{

dig[o]=0;

}

tr.clear();

}

String uarray[]=ustr.split(" ");

int unum[]=new int[uarray.length];

for( int t=0;t<uarray.length;t++)

{

Integer.parseInt(String.valueOf(uarray[t]));

unum[t]=Integer.parseInt(String.valueOf(uarray[t]));

sum=sum+unum[t];

}

System.out.println(sum);

}

}

#SPJ2

Similar questions