Home
/
Aktualności
/
Artykuł
/

Zadanie 2

using namespace std;

std::string replaceLastOccurrence(string tekst, string slowo)
{
string pierwsze = „”;
bool firstSet = false;

size_t lastPos = string::npos;
size_t lastLen = 0;

size_t i = 0;
while (i < tekst.size()) {
    while (i < tekst.size() && std::isspace((unsigned char)tekst[i])) i++;
    if (i >= tekst.size()) break;

    size_t j = i;
    while (j < tekst.size() && !std::isspace((unsigned char)tekst[j])) j++;

    string w = tekst.substr(i, j - i);

    if (!firstSet) {
        pierwsze = w;
        firstSet = true;
    }

    if (w == slowo) {
        lastPos = i;
        lastLen = j - i;
    }

    i = j;
}

if (!firstSet) return tekst;
if (lastPos == string::npos) return tekst;

return tekst.substr(0, lastPos) + pierwsze + tekst.substr(lastPos + lastLen);

}

int main()
{
string tekst, slowo;
getline(cin, tekst);
getline(cin, slowo);
cout << replaceLastOccurrence(tekst, slowo) << endl;
return 0;
}

Kategorie

Ostatnie

Zadanie 4

class Triangle{double _side1, _side2, _side3; public:Triangle(double a = 0, double b = 0, double c = 0) : _side1(a), _side2(b), _side3(c) {} }; int main(){int n;std::cin>>n;Triangle a(0, 0, 0);Triangle b(0,

Przeczytaj więcej »

Zadanie 1

Wektory dodaj includy using namespace std; vector roznicaWektorow(vector wektor1, vector wektor2){float avg1 = 0.0f, avg2 = 0.0f; } int main() {std::vector wektor1;std::vector wektor2;std::vector wynik;float input;while (std::cin >> input) {wektor1.push_back(input);if (std::cin.get()

Przeczytaj więcej »

Tagi

Kalendarz

kwiecień 2026
P W Ś C P S N
 12345
6789101112
13141516171819
20212223242526
27282930  

Pozostałe Wpisy

Zadanie 4

class Triangle{double _side1, _side2, _side3; public:Triangle(double a = 0, double b = 0, double c = 0) : _side1(a), _side2(b), _side3(c) {} }; int main(){int n;std::cin>>n;Triangle a(0, 0, 0);Triangle b(0, 0, 0);Triangle c(0, 0, 0);double s1, s2, s3;switch (n){case 1:a = Triangle();std::cout<<a.getSide(1)<<std::endl;std::cout<<a.getSide(2)<<std::endl;std::cout<<a.getSide(3)<<std::endl;break; }

Czytaj więcej ➭

Zadanie 3

using namespace std; int count_even_sums_and_sort_list(list& lista){int ile = (int)count_if(lista.begin(), lista.end(), [](int v) {if (v < 0) v = -v; int s = 0; do { s += v % 10; v /= 10; } while (v > 0);return (s % 2) == 0;}); } int main(){std::list lista;int n;while(std::cin>>n)lista.push_back(n); }

Czytaj więcej ➭

Zadanie 2

using namespace std; std::string replaceLastOccurrence(string tekst, string slowo){string pierwsze = „”;bool firstSet = false; } int main(){string tekst, slowo;getline(cin, tekst);getline(cin, slowo);cout << replaceLastOccurrence(tekst, slowo) << endl;return 0;}

Czytaj więcej ➭