×

# SUMALPHA - Editorial

Author: Chandan Boruah
Tester: Chandan Boruah
Editorialist: Chandan Boruah

CAKEWALK

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.

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();
for(int test=0;test<t;test++)
{
int sum=0;
for(int i=0;i<s.Length;i++)
{
sum+=Array.IndexOf(arr,s[i])%5;
}
Console.WriteLine(sum);
}
}
}


694
accept rate: 0%

17.8k347489518

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×12,923
×1,223
×97
×1

question asked: 10 Jan '17, 09:44

question was seen: 764 times

last updated: 10 Jan '17, 12:38