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.
Answers
Answer:
#include<stdio.h>
void main()
{
int N,j,num,largest=0,smallest=1000,remd,i,count,numOfPairs=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++)
{
num=numbers[j];
largest=0;
smallest=1000;
while (num > 0) {
remd = num % 10;
if (remd > largest)
{
largest = remd;
}
if (remd < smallest)
{
smallest = remd;
}
num = num / 10;
}
bitScore[j]=((largest*11)+(smallest*7))%100;
}
for(i=1;i<9;i++)
{
count=0;
for(j=0;j<N;j=j+2)
{
num=bitScore[j]/10;
if(num==i)
count++;
}
if(count==2)
numOfPairs++;
else if(count>=3)
numOfPairs=numOfPairs+2;
count=0;
for(j=1;j<N;j=j+2)
{
num=bitScore[j]/10;
if(num==i)
count++;
}
if(count==2)
numOfPairs++;
else if(count>=3)
numOfPairs=numOfPairs+2;
}
printf("%d", numOfPairs);
getchar();
}
Answer:
Step-by-step explanation:
N=int(input())
arr=list(map(int,input().split()))
bitscore=[]
oddnum=[]
evennum=[]
count=0
for num in arr:
num=str(num)
large=max(num)
small=min(num)
bit=str((int(large)*11+int(small)*7))
length=len(bit)
if(length>2):
bit=bit[-2:]
else:
bit=bit
bitscore.append(int(bit))
# print(bitscore)
odd=bitscore[::2]
even=bitscore[1::2]
for i in range(len(odd)):
temp=str(odd[i])[0]
oddnum.append(temp)
# print(oddnum)
for i in range(len(even)):
temp=str(even[i])[0]
evennum.append(temp)
# print(evennum)
for i in range(len(evennum)):
temp=evennum[i]
for j in range(i+1,len(evennum)):
if(temp==evennum[j]):
count=count+1
break
for i in range(len(oddnum)):
temp=oddnum[i]
for j in range(i+1,len(oddnum)):
if(temp==oddnum[j]):
count=count+1
break
print(count)