TCS NQT 2021 Program Answers

TCS NQT 2021 Coding 

29 october
5 pm slot

string=input("")
C=0
W=1
for i in string:
      C=C+1
      if(i==' '):
            W=W+1
print(C)
print(W)

28 october
5 pm slot

ranks=[0,0,0,0,0]
names=['Malaysia','Australia','Germany','Dubai','France']
flag=0

for i in range(0,5):
    if flag==1:
        break
    for j in range(0,5):
        r=input()
        if r.isnumeric():
            r=int(r)
            if r>0 and r<=5:
                if r==1:
                    ranks[j]+=1
            else:
                flag=1
                break
        else:
            flag=1
            break
if flag==1:
    print("INVALID INPUT")
else:
    comb=list(zip(ranks,names))
    comb.sort(key = lambda x:x[0])
    top = comb[0][0]
    for i in range(0,5):
        if top==comb[i][0]:
            print(comb[i][1])

Bunch of keys
x=[]
while True:
    x.append(input())
    if x[-1]=='q':
        break
x.remove('q')
p=x.count('-')
print("BLANK KEYS:"+str(p))
print("TOTAL KEYS:"+str(len(x)))
print("NUMBER OF LOCKS:"+str(len(x)-p)

26 october


c=["Expresso","Cappuccino","Latte"]
t=["Plain","Assam","Ginger","Cardamom","Masala","Lemon","Green","Organic Darjeeling"]
s=["Hot and Sour","Veg Corn","Tomato","Spicy Tomato"]
b=["Hot Choclate","Badam","Bdam-Pista"]
order=input()
num=int(input())
if order in ["c","t","s","b"]:
    if order=="c":
        if num<len(c) and num>0:
            print("Welcome to CCD!","\nEnjoy your",c[num-1],"Coffee!")
        else:
            print("INVALID OPTION!")
    if order=="t":
        if num<len(t) and num>0:
            print("Welcome to CCD!","\nEnjoy your",t[num-1],"Tea!")
        else:
            print("INVALID OPTION!")
    if order=="s":
        if num<len(s) and num>0:
            print("Welcome to CCD!","\nEnjoy your",s[num-1],"Soup!")
        else:
            print("INVALID OPTION!")
    if order=="b":
        if num<len(b) and num>0:
            print("Welcome to CCD!","\nEnjoy your",b[num-1],"Drink!")
        else:
            print("INVALID OPTION!")


25 october

Slot 3:





Program (python):

N = float(input())
M = str(N)
M = list(map(int,M.split(".")))
if(M[0]==10 and M[1]<=22):
  print("INVALID INPUT")
elif(((M[0]>=0 and M[0]<=23) and (M[1]>=0 and M[1]<=59))):
   print("{:.2f} {:.2f} {:.2f} {:.2f} {:.2f} {:.2f}".format(N,N+0.04,N+0.09,N+0.15,N+0.19,N+0.22))
else:
   print("INVALID INPUT")




def Search(PlateNumber):
    for pos,num in enumerate(CPS,1):
        if(PlateNumber==num):
            return pos
    return -1
def Park(PlateNumber):
    for pos,num in enumerate(CPS,1):
        if(PlateNumber==num):
            return (pos*2)
    return -1
    
a=int(input())
if(a==1 or a==2):
    number=input()
    numlen=len(number)
    if(numlen<6 or numlen>12):
        print("INVALID INPUT")
    elif(a==2):
        pos=Search(number)
        if pos>0:
            print("CAR POSITION:",pos,sep="")
        else:
            print("CAR DOES NOT EXISTS")
    elif(a==1):
        pos=Park(number)
        if(pos>0):
            print("CAR POSITION:",pos,sep="")
        else:
            print("INVALID INPUT")
else:
    print("INVALID INPUT")








CPS=["MH04CC2","MH04C2820","MH04BB3232","MH04CC2113","MH04CC2878","MH04BB8","MH04CC2888","MH04CC1313","MH04CC2222","MH04C1201","MH04CC555","MH04C6565","MH04A7"]
def Search(PlateNumber):
    for pos,num in enumerate(CPS,1):
        if(PlateNumber==num):
            return pos
    return -1
def Park(PlateNumber):
    for pos,num in enumerate(CPS,1):
        if(PlateNumber==num):
            return (pos*2)
    return -1
    
a=int(input())
if(a==1 or a==2):
    number=input()
    numlen=len(number)
    if(numlen<6 or numlen>12):
        print("INVALID INPUT")
    elif(a==2):
        pos=Search(number)
        if pos>0:
            print("CAR POSITION:",pos,sep="")
        else:
            print("CAR DOES NOT EXISTS")
    elif(a==1):
        pos=Park(number)
        if(pos>0):
            print("CAR POSITION:",pos,sep="")
        else:
            print("INVALID INPUT")
else:
    print("INVALID INPUT")

slot 2:



Python:

parent = input()
check=input()
if(parent.isalpha()!=1):
    print("INVALID INPUT")
elif(check=="Y"):
    child = input()
    childlist = child.split(",")
    print(childlist)
    n=len(childlist)
    print("TOTAL MEMBERS:",n+1,sep="")
    pcommission=n*5000*(10/100)
    print("COMMISSION DETAILS",sep="")
    print(parent,":",pcommission," INR",sep="")
    chcommission=5000*(5/100)
    for name in childlist:
        print(name,":",chcommission," INR",sep="")
    
elif(check=="N"):
    n=1
    print("TOTAL MEMBERS:",n,sep="")
    print("COMMISSION DETAILS")
    print(parent,":250 INR",sep="")
else:
    print("INVALID INPUT")


#include<stdio.h>

int main()
{
    int n,k,j,m,p;
    float atebanana=0.0,atepeanut=0.0;
    scanf("%d %d %d %d %d",&n,&k,&j,&m,&p);
    if(n<0 || k<0 || j<0 || m<0 || p<0)
    {
        printf("INVALID INPUT");
    }
    else
    {
        if(k>0)
            atebanana =(float)m/k;
        if(j>0)
            atepeanut =(float) p/j;
        n=n-atebanana-atepeanut;
        printf("Number of Monkeys left on the Tree:%d",n);
    }
    return 0;
}





C++:

#include "bits/stdc++.h"
#define ll long long
using namespace std;
int main()
{

    string par;
    cin >> par;
    string x;
    cin >> x;
    if (x == "N") {
        cout << "TOTAL MEMBERS:1\n";
        cout << "COMISSION DETAILS\n";
        cout << par << ":250 INR\n";
    } else {
        string child;
        cin >> child;
        vector<string>v;
        string temp = "";
        for (int i = 0; i < child.length(); i++) {
            if (child[i] == ',') {
                v.push_back(temp);
                temp = "";
            }
            else  if (child[i] != ' ')
                temp += child[i];
        }
        v.push_back(temp);
        cout << "TOTAL MEMBERS:" << v.size() + 1 << "\n";
        cout << "COMISSION DETAILS\n";
        cout << par << ":" << v.size() * 500 << " INR\n";
        for (auto a : v) {
            cout << a << ":" << "250 INR\n";
        }
    }
}

#include "bits/stdc++.h"
#define ll long long
using namespace std;
int main()
{

    string par;
    cin >> par;
    string x;
    cin >> x;
    if (x == "N") {
        cout << "TOTAL MEMBERS:1\n";
        cout << "COMISSION DETAILS\n";
        cout << par << ":250 INR\n";
    } else {
        string child;
        cin >> child;
        vector<string>v;
        string temp = "";
        for (int i = 0; i < child.length(); i++) {
            if (child[i] == ',') {
                v.push_back(temp);
                temp = "";
            }
            else  if (child[i] != ' ')
                temp += child[i];
        }
        v.push_back(temp);
        cout << "TOTAL MEMBERS:" << v.size() + 1 << "\n";
        cout << "COMISSION DETAILS\n";
        cout << par << ":" << v.size() * 500 << " INR\n";
        for (auto a : v) {
            cout << a << ":" << "250 INR\n";
        }
    }
}


slot 1:


program 2:

#include <bits/stdc++.h>
using namespace std;

int main() {
 
 string s , d;
 cin>>s>>d;
 
 transform(s.begin(),s.end() , s.begin(),::toupper);
 transform(d.begin(),d.end() , d.begin(),::toupper);
 
 string arrs[8] = {"TH" , "GA", "IC" , "HA" , "TE", "LU" ,"NI","CA"};
 float arr[8]={800,600,750,900,1400,1200,1100,1500};
 
 float res=0;
 int st ,ed;
 for(int i=0;i<8;i++)
 {
     if(s==arrs[i])
     st=i;
     if(d==arrs[i])
     ed=i;
  }
  if(st==ed)
  {
      cout<<" INVALID INPUT";
      return 0;
  }
  else
  {
      int i=st+1;
        while(i!=ed)
        {
            res+=(ceil)(arr[i]/200);
            i=(i+1)%8;
        }
        cout<<res;
        return 0;
  }
}

program 1:

inte=int(input())
ext=int(input())
i,e=[],[]
if inte<0 or ext<0:
    print("INVALID INPUT")
elif inte==0 and ext==0:
    print("Total estimated Cost:0 INR")
else:
    for x in range(inte):
        i+=[float(input())]
    for x in range(ext):
        e+=[float(input())]
    ans=(sum(i)*18)+(sum(e)*12)
    print("Total estimated Cost:",ans," INR",sep="")



#include <iostream>

using namespace std;

int main()
{
        int i, e, ic = 18, ec =12, n;
        cin>>i>>e;

        float si[i], se[e], I=0, E=0;
        for(n=0; n<i; n++){
                cin>>si[n];
                I = I + si[n];
        }
        for(n=0; n<e; n++){
                cin>>se[n];
                E = E + se[n];
        }

        float cost = I*ic + E*ec;

        cout<<cost;

        return 0;
}


#include<stdio.h>

int main()
{
    int ni,ne,i=0;
    float int_p=18,ext_p=12,cost=0,temp;
    scanf("%d %d",&ni,&ne);
    if(ni<0 || ne<0 )
    {
        printf("INVALID INPUT");
    }
    else if(ni==0 && ne==0)
    {
        printf("Total estimated Cost : 0.0");
    }
    else
    {
        for(i=0;i<ni;i++)
        {
            scanf("%f",&temp);
            cost+= int_p*temp;
        }
        for(i=0;i<ne;i++)
        {
            scanf("%f",&temp);
            cost+= ext_p*temp;
        }
        printf("Total estimated Cost : %.1f",cost);
    }
    return 0;
}


24 October


Slot 2:

program 1:

#include<stdio.h>
#include<string.h>

void customCaesarCipher(int key,char str[])
{
    int n=0,i=0;
    for(n=0;str[n]!='\0';n++);
    if(key<0)
    {
        printf("INVALID INPUT");
        return;
    }
    else
    {
        for(i=0;i<n;i++)
        {
            if(str[i]!=' ')
            {
              if(str[i]>=65 && str[i]<=90)
              {
                 if((int)(str[i]+key)<=90)
                    str[i] = (int) (str[i]+key);
                 else
                    str[i] = (int)(str[i]+key-90+65-1);
              }
              else if(str[i]>=97 && str[i]<=122)
              {
                 if((int)(str[i]+key)<=122)
                    str[i] = (int) (str[i]+key);
                 else
                    str[i] = (int)(str[i]+key-122+97-1);
              }
              else if((str[i]>=48 && str[i]<=57))
              {
                  if((int)(str[i]+key)<=57)
                    str[i] = (int)(str[i]+key);
                 else
                    str[i] = (int)(str[i]+key-57+48-1);
              }

            }

        }

        printf("%s",str);
    }

}
int main()
{
    int key;
    char str[100];
    scanf("%[^\n]s",str);
    scanf("%d",&key);

    customCaesarCipher(key,str);
    return 0;

}

program 2:

#include <stdio.h>
int main(int argc, char const *argv[])
{
  int n;
  scanf("%d",&n);
  int i=0;
  if(n==0){
    printf("Time Estimated:%dMinutes\n",n);
  }
  else if(n>0 && n<2001){
    i=25;
    printf("Time Estimated:%dMinutes\n",i);
  }
  else if(n>2000 && n<4001){
    i=35;
    printf("Time Estimated:%dMinutes\n",i);
  }
  else if(n>4000 && n<7000){
    i=45;
    printf("Time Estimated:%dMinutes\n",i);
  }
  else if(n>7000){
    printf("OVERLOADED!\n");
  }
  else{
    printf("INVALID INPUT\n");
  }
  return 0;
}

Slot: 8.00 am - 11.00 am

Hands on Exercise 1

Candies Problem



There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain maximum N candies when JAR is full. At any point of time. JAR can have M number of Candies where M<=N. Candies are served to the customers. JAR is never remain empty as when last k candies are left. JAR if refilled with new candies in such a way that JAR get full.
Write a code to implement above scenario. Display JAR at counter with available number of candies. Input should be the number of candies one customer can order at point of time. Update the JAR after each purchase and display JAR at Counter.

Output should give number of Candies sold and updated number of Candies in JAR.

If Input is more than candies in JAR, return: “INVALID INPUT”


Given,

N=10, where N is NUMBER OF CANDIES AVAILABLE

K =< 5, where k is number of minimum candies that must be inside JAR ever.


Example 1:(N = 10, k =< 5)

Input Value

3

Output Value

NUMBER OF CANDIES SOLD : 3

NUMBER OF CANDIES AVAILABLE : 7


Example : (N=10, k<=5)

Input Value

0

Output Value
INVALID INPUT

NUMBER OF CANDIES LEFT : 10

Python

i = int(input())
n = 10
k = 5
if(i >n):
     print(“INVALID INPUT”)
     print(“NUMBER OF CANDIES AVAILABLE:”, n)
elif(i == 0):
    print(“Invalid Input”)
    print(“NUMBER OF CANDIES AVAILABLE:”, n)
else:
    print(“NUMBER OF CANDIES SOLD:”, i)
    print(“NUMBER OF CANDIES AVAILABLE:”, n-i)

Selection of MPCS Problem:

Selection of MPCS exams include a fitness test which is conducted on ground. There will be a batch of 3 trainees, appearing for running test in track for 3 rounds.


You need to record their oxygen level after every round. After trainee are finished with all rounds, calculate for each trainee his average oxygen level over the 3 rounds and select one with highest oxygen level as the most fit trainee. If more than one trainee attains the same highest average level, they all need to be selected.


Display the most fit trainee (or trainees) and the highest average oxygen level.


Note:

The oxygen value entered should not be accepted if it is not in the range between 1 and 100.
If the calculated maximum average oxygen value of trainees is below 70 then declare the trainees as unfit with meaningful message as “All trainees are unfit”
Average Oxygen Values should be rounded.

Example 1:


INPUT VALUES

95

92

95

92

90

92

90

92

90


OUTPUT VALUES

Trainee Number : 1

Trainee Number : 3


Note:

Input should be 9 integer values representing oxygen levels entered in order as


Round 1

Oxygen value of trainee 1

Oxygen value of trainee 2

Oxygen value of trainee 3


Round 2

Oxygen value of trainee 1

Oxygen value of trainee 2

Oxygen value of trainee 3


Round 3

Oxygen value of trainee 1

Oxygen value of trainee 2

Oxygen value of trainee 3

JAVA:

public static void oxyGen() {
      Scanner scanner=new Scanner(System.in);
    int[] n=new int[9];
    for (int i = 0; i < n.length; i++) {
      n[i]=scanner.nextInt();
    }
    float a1,a2,a3;
    a1=n[0]+n[3]+n[6];
    a1=a1/3;
    a2=n[1]+n[4]+n[7];
    a2=a2/3;
    a3=n[2]+n[5]+n[8];
    a3=a3/3;

    if(Math.round(a1)<70 &&Math.round(a2)<70&& Math.round(a3)<70) {
      System.out.println("All tranees are unfit");
    return;
    }
    else {
    a1=Math.round(a1);
    a2=Math.round(a2);
    a3=Math.round(a3);

    if(a1>=a2 || a1>=a3 ) {
      System.out.println("Trainee Number 1");
    }
  if(a2>=a1 || a2>=a3 ){
    System.out.println("Trainee Number 2");

    }  if(a3>=a1 || a2>=a3) {
      System.out.println("Trainee Number 3");

    }
    }
    
      
  }

C:

#include<stdio.h>
int main()
{
    int a[3];
    int b[3];
    int c[3];
    float avg[3];
    int i,j,sum=0,max;
    for(i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
        scanf("%d",&b[i]);
        scanf("%d",&c[i]);
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            sum = sum + a[j];
        }
        avg[i] = sum/3;
        sum = 0;
    }
    max = avg[0];
    for(i=1;i<3;i++)
    {
        if(avg[i]>max)
        {
            max = avg[i];
        }
    }
    
    for(i=0;i<3;i++)
    {
        if(avg[i]==max)
        {
            if(max>70)
                printf("Trainee Number:%d\n",i+1);
            else
                printf("All trainees are unfit\n");
                break;
        }
    }
}

Comments