PROBLEM LINK:
Author: Chandan Boruah
Tester: Chandan Boruah
Editorialist: Chandan Boruah
DIFFICULTY:
CAKEWALK
PREREQUISITES:
Brute force.
PROBLEM:
Given a string print the sum of all the letter position (according to english alphabets) in the string. However, everytime the letter position is divisible by 5, the counter is set to 0.
Advanced EXPLANATION:
Use modulus by 5 in the letter alphabet position and then add up the value to the sum variable.
EXPLANATION:
Iterate over all the characters in the word. Find the position of the alphabet in the English alphabet either using characters in array or by converting the character to integer and do a modulo by 5 and add it to the counter thats including the sum.
TESTER’S SOLUTIONS:
using System;
class some
{
public static void Main()
{
char[]arr="abcdefghijklmnopqrstuvwxyz".ToCharArray();
int t=int.Parse(Console.ReadLine());
for(int test=0;test<t;test++)
{
string s=Console.ReadLine();
int sum=0;
for(int i=0;i<s.Length;i++)
{
sum+=Array.IndexOf(arr,s[i])%5;
}
Console.WriteLine(sum);
}
}
}