The base Output variable result is set to a default value of -404 which can be modified. Additionall y, you can add or remove these output variables. Input Format The first line contains an integer N denoting the size of the string.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 3PE
icon
Related questions
icon
Concept explainers
Question
Use python fast 20 minutes
2
3
ed.
The base Output variable result is set to a default
value of -404 which can be modified. Additionall
y, you can add or remove these output variables.
Input Format
The first line contains an integer N denoting the
size of the string.
The second line contains the input string S.
Sample Input
5
aaacc
Constraints
1 <= N <= 5
"a" <= S[i] <= "z" for every i from 0 <=i< N.
Output Format
Return a single integer denoting the total sum of
all the powers of every unique alphabet present i
n the string.
Sample Output
Explanation
The unique alphabets present in the string are
"a" and "c" with frequencies 3 and 2 respectively.
The power of "a" is its position in the alphabet
(1) raised to its occurrence (3). hence the power
of a = 13 = 1.
Similarly, the power of "c" is its position in the al
phabet (3) raised to its occurrence (2). hence the
power of "c" = 32 = 9.
Therefore, total power = power of a - power o
fc' = 9 + 1 = 10.
Hence, the output is 10.
Language
1
2345NON∞ 0
19
10
Test Case:
Transcribed Image Text:2 3 ed. The base Output variable result is set to a default value of -404 which can be modified. Additionall y, you can add or remove these output variables. Input Format The first line contains an integer N denoting the size of the string. The second line contains the input string S. Sample Input 5 aaacc Constraints 1 <= N <= 5 "a" <= S[i] <= "z" for every i from 0 <=i< N. Output Format Return a single integer denoting the total sum of all the powers of every unique alphabet present i n the string. Sample Output Explanation The unique alphabets present in the string are "a" and "c" with frequencies 3 and 2 respectively. The power of "a" is its position in the alphabet (1) raised to its occurrence (3). hence the power of a = 13 = 1. Similarly, the power of "c" is its position in the al phabet (3) raised to its occurrence (2). hence the power of "c" = 32 = 9. Therefore, total power = power of a - power o fc' = 9 + 1 = 10. Hence, the output is 10. Language 1 2345NON∞ 0 19 10 Test Case:
-1
2
3
Q1. Strings: Power of the string
Given string S contains lowercase alphabets.
The power of an alphabet is defined as the positi
on of the alphabet( i.e. A - 1, B - 2, C-3, D-4, E
5, F-6 and so on...) raised to the number of ti
mes the alphabet occurs in the given string.
Calculate the sum for the power of every unique
alphabet present in the string.
There will be multiple test cases running so the I
nput and Output should match exactly as provid
ed.
The base Output variable result is set to a default
value of -404 which can be modified. Additionall
y, you can add or remove these output variables.
Input Format
The first line contains an integer N denoting the
size of the string.
The second line contains the input string S.
Sample Input
5
aaacc
Constraints
1 <= N <= 5
"a" <= S[i] <= '2" for every i from 0 <=i< N.
Output Format
Return a single integer denoting the total sum of
all the powers of every unique alphabet present i
Langua
1
2-
2345 600 1
10
12
16
14
Test Case
Transcribed Image Text:-1 2 3 Q1. Strings: Power of the string Given string S contains lowercase alphabets. The power of an alphabet is defined as the positi on of the alphabet( i.e. A - 1, B - 2, C-3, D-4, E 5, F-6 and so on...) raised to the number of ti mes the alphabet occurs in the given string. Calculate the sum for the power of every unique alphabet present in the string. There will be multiple test cases running so the I nput and Output should match exactly as provid ed. The base Output variable result is set to a default value of -404 which can be modified. Additionall y, you can add or remove these output variables. Input Format The first line contains an integer N denoting the size of the string. The second line contains the input string S. Sample Input 5 aaacc Constraints 1 <= N <= 5 "a" <= S[i] <= '2" for every i from 0 <=i< N. Output Format Return a single integer denoting the total sum of all the powers of every unique alphabet present i Langua 1 2- 2345 600 1 10 12 16 14 Test Case
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT