Join Regular Classroom : Visit ClassroomTech

TCS NQT Previous Year Solve | Day 2 | Slot 2 (V) | Codewindow.in

Coding

//Solution in C++
#include <iostream>
using namespace std;

int main() {
	int weight;
	cin >> weight;
	if(weight < 0)
	    cout << "INVALID INPUT";
	else if(weight == 0)
	    cout<<"Time Estimated : 0 Minutes";
	else if(weight > 0 && weight <= 2000)
	    cout << "Time Estimated : 25 Minutes";
	else if(weight > 2001 && weight <= 4000)
	    cout << "Time Estimated : 35 Minutes";
	else if(weight > 4001 && weight <= 7000)
	    cout << "Time Estimated : 45 Minutes";
	else
	    cout << "OVERLOADED!";
	return 0;
}
//Solution in C++
#include <iostream>
using namespace std;

int main() {
	int key;
	char str[100];
	scanf("%[^\n]s",str);
	scanf("%d",&key);
	customCaesarCipher(key,str);
	return 0;
}
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);
}
}
Categories
Pages
Recent Posts