Tuesday, December 27, 2022

MFIB Comma Separated Integers

Fill in the blanks with code so that the program must accept three integers separated by a space and print them separated by a comma as the output

Input Format:

The first line contains three integers separated by a space.


Output Format:

The first line contains three integers separated by a comma.


Example Input/Output:

217 18

21,7,18


Solution:

X, Y, Z = map(int, input().split()) 

print(X, Y, Z,sep="," )

MFIB Maximum of Three

Fill in the blanks with code so that the program must accept three integers X, Y and Z as the input. The program must print the maximum integer among the three integers as the output.

Input Format:

The first line contains X, Y and Z separated by a space.


Output Format:

The first line contains the maximum integer among the three integers.


Example Input/Output :

Input:

589
9

Solution:

X, Y, Z = [int(val) for val in input().split()]

print(X if X>Y and X>Z else Y if Y>Z else Z )

MFIB- All Unique or Not

Fill in the blanks with code so that the program accepts a list of integers and prints YES if all the integers in the list are unique. Else the program prints NO as the output.

Input Format:

The first line contains the list of integers separated by a space.

Output Format:

The first line contains YES or NO.

Example Input/Output :

7893

YES


Solution:


numList=list(map(int,input().split()))

if len(numList)==len(set(numList)):

    print("YES")

else:

    print("NO")

Friday, September 9, 2022

Alternate letters in uppercase in python


A str‌ing (only alphabets) is passed as input.
The printed output should contain alphabets in odd positions in each word in uppercase and alphabets in even positions in a word in lowercase.

Example input/output1:

If the input is 'tREE GiVES us fruiTS', the output should be 'TrEe GiVeS Us FrUiTs

If the input is 'FLoweR iS beauTIFUL', the output should be 'FlOwEr Is BeAuTiFuL'

Solution:

s=list(input().split())

for i in range(len(s)):

    t=""

    for j in range(len(s[i])):

        if j%2!=0:

            t+=s[i][j].lower()

        else:

            t+=s[i][j].upper()

    s[i]=t 

for i in s:print(i,end=" ")

Alternate letters in uppercase in Java

A str‌ing (only alphabets) is passed as input.
The printed output should contain alphabets in odd positions in each word in uppercase and alphabets in even positions in a word in lowercase.

Example input/output1:

If the input is 'tREE GiVES us fruiTS', the output should be 'TrEe GiVeS Us FrUiTs

If the input is 'FLoweR iS beauTIFUL', the output should be 'FlOwEr Is BeAuTiFuL

Solution:

           import java.util.*;

  class Hello {

  public static void main(String[] args) {

  Scanner sc=new Scanner(System.in);

  String str=sc.nextLine();

  String[] input=str.split("[ ]");

  char[] ch=new char[str.length()];

  int i,j;

  for(i=0;i<input.length;i++)

  {

      ch=input[i].toCharArray(); 

     for(j=0;j<ch.length;j++)

     {

         if(j%2==0)

          System.out.print(Character.toUpperCase(ch[j]));

          else if(j%2==1)

          System.out.print(Character.toLowerCase(ch[j]));

     }

     System.out.print(" ");

  }

Sunday, June 14, 2020

sum of closest float values in c

Three floating point values are passed as the input to the program. The program must print the sum of two numbers which are closest to each other with the precision up to 2 decimal places.

Example Input/Output 1:
Input:
2.45 6.78 2.35

Output:
4.80

solution:

int main()

{

float a,b,c;

scanf("%f %f %f",&a,&b,&c);

if(abs(a-b)<abs(b-c) && abs(a-b)<abs(a-c)){

    printf("%.2f",a+b);

}

else if(abs(b-c)<abs(a-b) && abs(b-c)<abs(a-c)){

    printf("%.2f",b+c);

}

else{

    printf("%.2f",a+c);

}


}

largest floating point value in c

Three floating point numbers are passed as the input to the program. The program must print the number which has the largest floating point value in it.

Example Input/Output 1:
Input:
12.45 7.89 30.56

Output:
7.89


solution:

int main()

{

float a,b,c;

scanf("%f %f %f",&a,&b,&c);

float m=a-(int)a;

float n=b-(int)b;

float o=c-(int)c;

if(m>n && m>o){

    printf("%.2f",a);

}

else if(n>m && n>o){

    printf("%.2f",b);

}

else{

    printf("%.2f",c);

}


}

MFIB Comma Separated Integers

Fill in the blanks with code so that the program must accept three integers separated by a space and print them separated by a comma as the ...