All pastes #993545 Raw Edit

Someone

public text v1 · immutable
#993545 ·published 2008-04-22 18:24 UTC
rendered paste body
#include <string>
#include <iostream>

using namespace std;

string str = "a  bc   def";
string new_str = "";

int length = str.length();

int get_spaces_num(string str, int index)
{
    int spaces_num = 0;

    while (str[index++] == ' ')
        spaces_num++;

    return spaces_num;
}

int main()
{
    for (int i = 0; i < length; i++)
    {
        if (str[i] == ' ')
            i += get_spaces_num(str, i) - 1;
        new_str += str[i];
    }

    cout << new_str << endl;
    return 0;
}