- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
#include <iostream>
#include <string>
using namespace std;
/*
*/
int change_word(const int begin_pos, string &words, int k, char c)
{
int pos = begin_pos;
int char_count = 0;
bool replaced = false;
while(pos < words.length() && isalpha(words[pos]))
{
char_count++;
if(char_count == k && !replaced)
{
words[pos] = c;
replaced = true;
}
pos++;
}
return pos;
}
void change_words(string &words, int k, char c)
{
int i = 0;
while(i < words.length())
{
if(isalpha(words[i]))
{
i = change_word(i, words, k, c);
}
else
{
i++;
}
}
}
int main()
{
char c = '>';
int k = 0;
string words = "Length of the substring to be copied";
cout << "enter number:";
cin >> k;
change_words(words, k, c);
cout << "changed text: " << words << endl;
return 0;
}