# [CodeWars] Mumbling

This time no story, no theory. The examples below show you how to write function `accum`:

Examples:

``````Accumul::accum("abcd");    // "A-Bb-Ccc-Dddd"
Accumul::accum("RqaEzty"); // "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
Accumul::accum("cwAt");    // "C-Ww-Aaa-Tttt"
``````

The parameter of accum is a string which includes only letters from `a..z` and `A..Z`.

### My Solution

 class Accumul{public:    static std::string accum(const std::string &s);};std::string Accumul::accum(const std::string &s){    std::string result;    for (int i = 0; i < s.length(); ++i)    {        if(i != 0)            result += ‘-‘;        result += s[i] < ‘a’ ? s[i] : (char)(s[i] – 32);        for (int j = 1; j <= i; ++j)            result += s[i] < ‘a’ ? (char)(s[i] + 32) : s[i];    }    return result;}Colored by Color Scripter cs

There are three rules to this problem. First, the repetition time of each alphabet increases by 1. Second, if the alphabet is uppercase, change it to all lowercase letters except the first alphabet. Third, if the first alphabet is lowercase, change it to uppercase.

So, write the code is correct for each condition, the others are simple. ## 글쓴이: BakJH

Student of Daedeok SW Meister Highschool, in Korea.

카테고리 Algorithm, Programming태그 ,