PROBLEM LINK:
Practice
Contest
Author: Yash Shah
Tester: Roshan Gupta, Shivam Sarang, Hrishikesh Patel
Editorialist: Yash Shah
DIFFICULTY: EASY
PREREQUISITES: Math
PROBLEM:
Ram loves to solve problems and spend all his time either solving
problems or playing COC. One day while solving a problem, he
defined ‘Beautiful Strings’.
Given an alphanumeric string made up of digits and lower case
Latin characters only.
A string ‘s’ is called ‘Beautiful’ if and only if, it’s length is equal to
sum of all the digit characters in the string.
EXPLANATION:
Sample Test case:
Input:
2
ab24da
b12ca
Output:
Beautiful
Not Beautiful
- Test Case 1: The length of string is 6 and digits in this string are
2 and 4. Hence, the sum of all of them is 6 which is equal to its
length therefore string is called ‘Beautiful’. - Test Case 2: The length of string is 5 and digits in this string are
1 and 2. Hence, the sum of all of them is 3 which is not equal to
its length therefore string is called ‘Not Beautiful’.
SOLUTIONS:
Setter's Solution
t = int(input())
while (t):
s = input()
ans = 0
for i in s:
if (i.isdigit()):
ans += int(i)
if len(s) == ans:
print("Beautiful")
else:
print("Not Beautiful")
t -= 1