TCS NQT Coding Questions (21st Feb, 2021)

There were basically two TCS NQT Coding Questions on Feb 21st, 2021. One of them asked to find the area of the circle and the other had to do with alteration in the input String. We will discuss the solution of the questions below.

Question 1.

Given an input string, you have to encrypt the string in such a manner that ‘a’ becomes ‘z’, ‘z’ becomes ‘a’ and accordingly.

 

Input format

The input is a lower case string

 

Output format

Encrypted lower case string

 

Example

Input:
programming

Output:
kiltiznnrmt

Solution

Language – C++

#include<iostream>
using namespace std;
int main() {
   string s, news=””;
   cin>>s;
   int len=s.length(); //finding the length of the string
   for(int i=0;i<len;i++) {
      char ch=s.at(i); //gives the character at different postions
      int pos=(int)ch;
      if(pos>=97 && pos<=122) {
         int newpos=122-(pos-97); //finding the encrypted character
         char newch=(char)newpos;
         news=news+newch; //concatenating the encrypted character in a new string
         }
      else {
         news=””;
         break;
         }
      }
   cout<<news<<endl;
   }

Language – Python

n = int(input())
for items in range(0,n):
   l=[]
   str = input()
   for x in range(len(str)):
      l.append(chr(122-(ord(str[x])-97)))
      print(“”.join(l))

 

Question 2.

Given an input integer T. For each T,  you have to accept an integer and calculate the area of the area of the circle using that integer as the radius.

Area of Circle = πr²

 

Input

T determining the number of testcases. For each testcase, radius of the circle.

NOTE – The radius should be in range 20-30.

 

Output

Area of circle with the radius passed as input for every testcase nearest to decimal place. If the radius is out of range, print “Radius not in range”

 

Example

Input:
3
22
10
25 Output: 1520.53
Radius not in range
25
1963.49

Solution

Language – C++

#include<iostream>
using namespace std;
int main() {
   int T;
   cin>>T;
   while(T–) {
      int radius;
      cin>>radius;
         if(radius>=20 && radius<=30) {
            float area=(float)3.14159*radius*radius;
            cout<<area<<endl;
         }
      else
         cout<<“Radius not in range”<<endl;
   }

Language – Python

n = int(input())
for x in range(n):
   radius = int(input())
   if ((radius >= 20) and (radius <= 30)):
      area = 3.14159 * radius * radius
      print(area)
   else:
      print(“Radius not in range”)

Don’t forget to comment your answers and queries below. More coding questions that were asked previously in TCS NQT will be updated soon.

Related Links

    • TCS NQT Coding Questions (6th May 2021) – Click Here

Leave a Reply