

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find letter's position in Alphabet using Bit operation in C++
In this problem, we are given a string str consisting of english alphabets. Our task is to find the letter's position in the Alphabet using the Bit operation.
Problem Description: Here, we will return the position of each character of the string as it is in english alphabets.
The characters of the string are case-insensitive i.e. “t” and “T” are treated the same.
Let’s take an example to understand the problem,
Input: str = “Tutorialspoint”
Output: 20 21 20 15 18 9 1 12 19 16 15 9 14 20
Solution Approach
A simple solution to find a character's position is by finding its logical AND operation with 31.
Program to illustrate the working of our solution,
Example
#include <iostream> using namespace std; void findLetterPosition(string str, int n) { for (int i = 0; i < n; i++) { cout<<(str[i] & 31) << " "; } } int main() { string str = "TutorialsPoint"; int n = str.length(); cout<<"The letters position in string "<<str<<" is \n"; findLetterPosition(str, n); return 0; }
Output
The letters position in string TutorialsPoint is 20 21 20 15 18 9 1 12 19 16 15 9 14 20
- Related Questions & Answers
- Replace a letter with its alphabet position JavaScript
- Swapping letter with succeeding alphabet in JavaScript
- Convert number to alphabet letter JavaScript
- Find position of the only set bit in C++
- 8086 program to reverse 16 bit number using 8 bit operation
- 8086 program to reverse 8 bit number using 8 bit operation
- Write a Golang program to find odd and even numbers using bit operation
- Position of rightmost set bit in C++
- Position of rightmost different bit in C++
- Golang Program to find the position of the rightmost set bit
- Find position of left most dis-similar bit for two numbers in C++
- Position of rightmost common bit in two numbers in C++
- Find Duplicates of array using bit array in Python
- Find Duplicates of array using bit array in C++
- Update the bit in the given position or Index of a number using C++
Advertisements