Witam, jestem dosyć nowy w C++ i mam problem z pewnym zadaniem. Otóż miałem stworzyć trzy funkcje - string papuga (string) - miała ona powielać każdą literę w danym ciągu znaków, papuga2, która miała powielać każdy co n-ty znak, gdzie n wprowadza użytkownik oraz papuga3 która miała powielać każdy znak tyle razy, którym znakiem jest w ciągu, np. jeden -> jeedddeeeennnnn. O ile udało mi się stworzyć zarówno funkcję papuga jak i papuga2, z tą 3 nie mogę sobie poradzić. Jest ktoś w stanie mi pomóc?
#include <string>
using namespace std;
string papuga (string);
string wspak (string);
string papuga2 (string, int);
int main () {
string napis; cin >> napis;
int n; cout << "Podaj n: "; cin >> n;
cout << "zad. 1" << endl << papuga(napis) << endl;
cout << "zad. 2" << endl << wspak (napis) << endl;
cout << "zad. 3" << endl << papuga2(napis, n) << endl;
}
string papuga (string napis) {
string wynik = "";
int dl = napis.length();
for (int i = 0; i < dl; i++) {
wynik = wynik+napis[i]+napis[i];
}
return wynik;
}
string wspak (string napis) {
string wynik = "";
int dl = napis.length();
for (int i = 0; i < dl; i++) {
wynik = napis[i] + wynik;
}
return wynik;
}
string papuga2 (string napis, int n) {
string wynik;
int dl = napis.length();
for (int i = 0; i < dl; i++) {
if ((i+1) % n == 0) wynik = wynik + napis[i] + napis[i];
else wynik = wynik + napis[i];
}
return wynik;
}
string papuga3(string napis) {
string wynik = "";
int dl = napis.length();
for (int i = 0; i < dl; i++) {
}
}