Given N three-digit numbers, your task is to find bit score of all N numbers and then print the number of pairs possible based on these calculated bit score.
1. Rule for calculating bit score from three digit number:
From the 3-digit number,
extract largest digit and multiply by 11 then
extract smallest digit multiply by 7 then
add both the result for getting bit pairs.
Note: -Bit score should be of 2-digits, if above results in a 3-digit bit score, simply ignore most significant digit.
Consider following examples:
Say, number is 286
Largest digit is 8 and smallest digit is 2
So, 8*11+2*7 =102 so Ignore most significant bit, So bit score = 02.
Say, Number is 123
Largest digit is 3 and smallest digit is 1
So, 3*11+7*1=40, so bit score is 40.
2. Rules for making pairs from above calculated bit scores
Condition for making pairs are
Both bit scores should be in either odd position or even position to be eligible to form a pair.
Palrs can be only made if most significant digit are same and at most two pair can be made for a given significant digit.
- Constraints
500
answer in c programming language
Answers
Answer:
#include<stdio.h>
void main()
{
int n,N,j,large=0,small=1000,remd,i,sum,Pairs=0;
int numbers[500],bitScore[500];
char tem;
scanf("%d",&N);
j=0;
do {
scanf("%d%c", &numbers[j], &tem);
j++;
} while(tem != '\n');
for(j=0;j<N;j++)
{
n=numbers[j];
large=0;
small=1000;
while (n > 0) {
remd = n % 10;
if (remd > large)
{
large = remd;
}
if (remd < small)
{
small = remd;
}
n /=10;
}
bitScore[j]=((large*11)+(small*7))%100;
}
for(i=1;i<9;i++)
{
sum=0;
for(j=0;j<N;j=j+2)
{
n=bitScore[j]/10;
if(n==i)
sum++;
}
if(sum==2)
Pairs++;
else if(sum>=3)
Pairs+=2;
sum=0;
for(j=1;j<N;j=j+2)
{
n=bitScore[j]/10;
if(n==i)
sum++;
}
if(sum==2)
Pairs++;
else if(sum>=3)
Pairs+=2;
}
printf("%d", Pairs);
}
Note: printf() function is used to print the character, string, float, integer, octal and hexadecimal values onto the display screen
scanf() function is used to read a character, string, numeric data through the keyboard.
#include<stdio.h> is a statement which tells the compiler to insert the contents of stdio at that particular place.