You are not logged in. Please login at www.codechef.com to post your questions!

×

SUMALPHA - Editorial

PROBLEM LINK:

Practice
Contest

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);
        }
    }
}

asked 10 Jan, 09:44

chandubaba's gravatar image

3★chandubaba ♢
713
accept rate: 0%

edited 10 Jan, 12:38

admin's gravatar image

0★admin ♦♦
17.1k347485513

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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,076
×1,125
×94
×1

question asked: 10 Jan, 09:44

question was seen: 724 times

last updated: 10 Jan, 12:38