Here is my code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string countAndSay(int);
int main(){
int n{};
cin >> n;
cout << countAndSay(n) << endl;
return 0;
}
string countAndSay(int n ){
static string s{"1"};
int count{n},special{n};
string one{"1"},two{"2"},three{"3"},trans{};
for(size_t i = 0 ; i < s.size() ; i++){
char c0 = s[i-1], c = s[i], c2 = s[i+1], c3 = s[i+2];
if(c!=c2 && c!=c0){
trans+=one+c;
}
if(c==c2 && c!=c3 && c!=c0){
trans+=two+c;
}
if(c==c2 && c==c3 && c!=c0){
trans+=three+c;
}
}
s.replace(0, s.size() , trans);
if(special != 1){
int N = --count;
if(N == 1)
return s;
else
return countAndSay(N);
}else
return "1";
}
these are the errors in cmd
C:\Users\saurabh rajput>gcc -o cas cas.cpp c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x25): undefined reference to std::cin' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x2a): undefined reference to
std::istream::operator>>(int&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4d): undefined reference to std::cout' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x52): undefined reference to
std::basic_ostream<char, std::char_traits >& std::operator<< <char, std::char_traits, std::allocator >(std::basic_ostream<char, std::char_traits >&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x59): undefined reference to std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x60): undefined reference to
std::ostream::operator<<(std::ostream& ()(std::ostream&))' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x6d): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x80): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0xa4): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0xcc): undefined reference to
__cxa_guard_acquire' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0xe6): undefined reference to std::allocator<char>::allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0xfe): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(char const, std::allocator const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x10d): undefined reference to __cxa_guard_release' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x123): undefined reference to
std::allocator::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x139): undefined reference to std::allocator<char>::allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x154): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x161): undefined reference to std::allocator<char>::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x16b): undefined reference to
std::allocator::allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x186): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x193): undefined reference to
std::allocator::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x19d): undefined reference to std::allocator<char>::allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x1b8): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x1c5): undefined reference to std::allocator<char>::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x1d2): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x1e3): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x204): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator[](unsigned int)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x21d): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x239): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator[](unsigned int)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x255): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x2a0): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator+=(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x2ad): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x2f8): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator+=(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x305): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x350): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::operator+=(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x35d): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x370): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::size() const' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x38f): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::replace(unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x3b7): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x3da): undefined reference to std::allocator<char>::allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x3f0): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string(char const*, std::allocator const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x3fd): undefined reference to std::allocator<char>::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x40a): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x417): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x424): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x431): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x442): undefined reference to
std::allocator::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x457): undefined reference to __cxa_guard_abort' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x46d): undefined reference to
std::allocator::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x483): undefined reference to std::allocator<char>::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x491): undefined reference to
std::allocator::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x49f): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4ad): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4bb): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4c9): undefined reference to
std::allocator::~allocator()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4da): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4e7): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x4f4): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x501): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x523): undefined reference to std::ios_base::Init::~Init()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text+0x544): undefined reference to
std::ios_base::Init::Init()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text$ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5[_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5]+0x17): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text$_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5_[__ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5_]+0x31): undefined reference to
std::__cxx11::basic_string<char, std::char_traits, std::allocator >::append(unsigned int, char)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.text$ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5[_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5]+0x40): undefined reference to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.eh_frame+0x13): undefined reference to
__gxx_personality_v0' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\SAURAB~1\AppData\Local\Temp\ccsa08IU.o:cas.cpp:(.eh_frame$ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_S5+0x13): undefined reference to `__gxx_personality_v0' collect2.exe: error: ld returned 1 exit status
Aucun commentaire:
Enregistrer un commentaire