The program must accept N alphabets as the input. The program must print the alphabet position of each alphabet in reverse order as the output.
Boundary Condition(s):
1 <= N <= 10^5
Input Format:
The first line contains the integer N.
The second line contains N characters separated by space(s).
Output Format:
The first line contains the alphabet position of N alphabets in the reverse order.
Example Input/Output 1:
Input:
5
j a e E b
Output:
2 5 5 1 10
Explanation:
The alphabet position of j is 10 in the alphabetical order.
The alphabet position of a is 1 in the alphabetical order.
The alphabet position of e is 5 in the alphabetical order.
The alphabet position of E is 5 in the alphabetical order.
The alphabet position of b is 2 in the alphabetical order.
In the reverse order, the alphabets position are 2 5 5 1 10
Hence the output is 2 5 5 1 10
Example Input/Output 2:
Input:
4
L f V d
Output:
4 22 6 12
#include <stdio.h>
#include <ctype.h>
int main() {
int n;
scanf("%d", &n);
char arr[n];
for(int i = 0; i < n; i++) {
scanf(" %c", &arr[i]);
}
for(int i = n - 1; i >= 0; i--) {
printf("%d ", tolower(arr[i]) - 'a' + 1);
}
return 0;
}
n = int(input())
alphabets = list(input().split())
positions = [str(ord(ch.lower()) - ord('a') + 1) for ch in alphabets]
print(' '.join(positions[::-1]))
import java.util.Scanner;
public class AlphabetPosition {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
char[] arr = new char[n];
for(int i = 0; i < n; i++) {
arr[i] = scanner.next().charAt(0);
}
for(int i = n - 1; i >= 0; i--) {
System.out.print(Character.toLowerCase(arr[i]) - 'a' + 1 + " ");
}
}
}
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
char arr[n];
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
for(int i = n - 1; i >= 0; i--) {
cout << tolower(arr[i]) - 'a' + 1 << " ";
}
return 0;
}
Leave a Reply