Recognize Me- Editorial

PROBLEM LINK:

[Practice ] (CodeChef: Practical coding for everyone)

Author: [Siddharth Jha]
(https://www.codechef.com/users/sidjha69)

DIFFICULTY:

SIMPLE

PREREQUISITES:

Observation, Conditional Statements

PROBLEM:

Take input from user and print the type of data whether it is a lower case or upper case letter or a digit or special characters.

QUICK EXPLANATION:

According to the range corresponding number was to be printed

SOLUTIONS:

Setter's Solution

//Using Ascii code
#include <iostream>

using namespace std; 

int solve (char a) {
     if ((int)a >= 48 && (int)a <= 57) return 0; 
     if ((int)a >= 65 && (int)a <= 90) return 1;
     if ((int)a >= 97 && (int)a <= 122) return 2;
     else return 3;
}

int main() {
    char a;
    cin >> a;
    cout << solve(a);
    return 0;
}

Tester's Solution

// Without using ascii code
#include <iostream>

using namespace std; 

int solve (char a) {

     if (a >= '0' && a <= '9') return 0;

     if (a >= 'A' && a <= 'Z') return 1;

     if (a >= 'a' && a <= 'z') return 2;

     else return 3;

}

int main() {

    char a;

    cin >> a;

    cout << solve(a);

    return 0;

}