Your browser is not supported. Please, update your browser or switch to a different one. Learn more about which browsers are supported.
Task description
Let us define a transformation that, given a string S of letters 'a' and/or 'b', replaces some consecutive sequence "abb" in S by "baa".
For example, after applying such a transformation to the string "abbabb", both strings "baaabb" and "abbbaa" can be obtained.
Write a function:
string solution(string &S);
that, given a string S of length N, returns the alphabetically largest string that can be obtained by performing the above operation any number of times.
Examples:
1. Given S = "ababb", your function should return "baaaa".
"baaaa" is alphabetically the largest possible outcome and may be obtained from "ababb" by using two transformations:
"ababb" → "abbaa" → "baaaa"
2. Given S = "abbbabb", your function should return "babaaaa".
"babaaaa" may be obtained from "abbbabb" by using three transformations:
"abbbabb" → "abbbbaa" → "baabbaa" → "babaaaa"
3. Given S = "aaabab", your function should return "aaabab".
No operation can be performed on S since it contains no "abb" fragment.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S is made only of the characters 'a' and/or 'b'.
Task timeline
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
if(S.begin(),S.end(),a)
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
if(S.begin(),S.end(),a !)
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
if(S.begin(),S.end(),a != S.end())
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
if(S.begin(),S.end(),a )
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto it = find(S.begin(),S.end(),a);
if
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find()
if
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita !=S.end())
{
}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita !=S.end())
{
//replace
}
else
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita !=S.end())
{
//replace
}
else i
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita !=S.end())
{
//replace
}
else if(itb != S.end())
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita !=std::string::npos)
{
//replace
}
else if(itb != S.end())
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita !=std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
func.cpp: In function 'std::__cxx11::string solution(std::__cxx11::string&)': func.cpp:13:8: error: no match for 'operator!=' (operand types are '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' and 'const size_type {aka const long unsigned int}') if(ita != std::string::npos) ~~~~^~~~~~ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:64:0, from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_pair.h:376:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&) operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) ^~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_pair.h:376:5: note: template argument deduction/substitution failed: func.cpp:13:24: note: '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' is not derived from 'const std::pair<_T1, _T2>' if(ita != std::string::npos) ^~~~ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:67:0, from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_iterator.h:304:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&) operator!=(const reverse_iterator<_Iterator>& __x, ^~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_iterator.h:304:5: note: template argument deduction/substitution failed: func.cpp:13:24: note: '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' is not derived from 'const std::reverse_iterator<_Iterator>' if(ita != std::string::npos) ^~~~ In file includ
// you can use includes, for example:
#include <algorithm>
#include <header>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <String>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
func.cpp:3:18: fatal error: String: No such file or directory #include <String> ^ compilation terminated.
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end(),a);
auto itb = find(S.begin(),S.end(),b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
func.cpp: In function 'std::__cxx11::string solution(std::__cxx11::string&)': func.cpp:13:8: error: no match for 'operator!=' (operand types are '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' and 'const size_type {aka const long unsigned int}') if(ita != std::string::npos) ~~~~^~~~~~ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:64:0, from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_pair.h:376:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&) operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) ^~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_pair.h:376:5: note: template argument deduction/substitution failed: func.cpp:13:24: note: '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' is not derived from 'const std::pair<_T1, _T2>' if(ita != std::string::npos) ^~~~ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:67:0, from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/stl_iterator.h:304:5: note: candidate: template<class _Iterator> bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&) operator!=(const reverse_iterator<_Iterator>& __x, ^~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/bits/stl_iterator.h:304:5: note: template argument deduction/substitution failed: func.cpp:13:24: note: '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' is not derived from 'const std::reverse_iterator<_Iterator>' if(ita != std::string::npos) ^~~~ In file includ
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = find(S.begin(),S.end()a);
auto itb = find(S.begin(),S.end(),b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
//replace
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace()
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(a)
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(a,S.find(a))
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
//replace
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
S.replace(S.find(b),b.size(),b);
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
S.replace(S.find(b),b.size(),a);
}
else{}
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
S.replace(S.find(b),b.size(),a);
}
else{}
return S
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
S.replace(S.find(b),b.size(),a);
}
else{}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
if(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
S.replace(S.find(b),b.size(),a);
}
else{}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
whi(ita != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if(itb != std::string::npos)
{
S.replace(S.find(b),b.size(),a);
}
else{}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
}
else if()
{
S.replace(S.find(b),b.size(),a);
}
else{}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
}
else{}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
ita = S.find(a);
itb = S.find(b);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
ita = S.find(a);
itb = S.find(b);
}
return S
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
ita = S.find(a);
itb = S.find(b);
}
return S
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
Cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S
}
func.cpp: In function 'std::__cxx11::string solution(std::__cxx11::string&)': func.cpp:19:5: error: 'Cout' was not declared in this scope Cout<<S<<endl; ^~~~ func.cpp:25:1: error: expected ';' before '}' token } ^
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S
}
func.cpp: In function 'std::__cxx11::string solution(std::__cxx11::string&)': func.cpp:25:1: error: expected ';' before '}' token } ^
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.find(a),a.size(),b);
S.replace(S.find(b),b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S;
}
ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ababb ab
abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb abbbabb
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(S.f,a.size(),b);
S.replace(S.find(b),b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(ita,a.size(),b);
S.replace(itb,b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(ita,a.size(),b);
S.replace(itb,b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S;
}
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 5)
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 7)
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"};
auto ita = S.find(a);
auto itb = S.find(b);
while(ita != std::string::npos
|| itb != std::string::npos)
{
S.replace(ita,a.size(),b);
S.replace(itb,b.size(),a);
cout<<S<<endl;
ita = S.find(a);
itb = S.find(b);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
while(ita != std::string::npos)
{
S.replace(ita,a.size(),b);
ita = S.find(a);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
while(ita != std::string::npos)
{
S.replace(ita,a.size(),b);
ita = S.find(a);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
while(ita != std::string::npos)
{
S.replace(ita,a.size(),b);
ita = S.find(a);
}
return S;
}
// you can use includes, for example:
#include <algorithm>
#include <string>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
string solution(string &S) {
// write your code in C++14 (g++ 6.2.0)
string a{"abb"}; string b{"baa"};
auto ita = S.find(a);
while(ita != std::string::npos)
{
S.replace(ita,a.size(),b);
ita = S.find(a);
}
return S;
}
The following issues have been detected: timeout errors.
Simple big test. N = 100,000. Score x 3.
Killed. Hard limit reached: 6.000 sec.