0
Pig Latin c++
Hi! The code works but I feel like I wrote a lot of code to something that probably can be solved in a easier way, if anyone knows how to solve it with less code I'll really appreciate it https://code.sololearn.com/cgB2RtYvFXcM/?ref=app
6 odpowiedzi
+ 3
What about:
#include <iostream>
#include <string>
using namespace std;
int main()
{
for(string p; cin>>p;) cout << p.substr(1) << p[0] << "ay ";
}
Anyway, your code has some mistakes in it, I think you should be more concerned about those
+ 2
This is my code.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string input;
getline(cin, input);
vector<string> col;
for(size_t i = 0, g = 0; i < input.length()+1; ++i)
{
if(input[i] == ' ' || i==input.length())
{
col.push_back(input.substr(g, i-g));
g = i+1;
}
}
for(auto& str : col)
{
cout << str.substr(1, str.length()-1) << str[0] << "ay ";
}
return 0;
}
+ 1
Itzel Medina
line 12: sizeof(palabra) is not the length of the string
line 15: palabra[j+2]!=0 will not count single character words at the end of the sentence
line 27: palabras[i] not checking for i<15 may lead to undefined behavior
line 29-36: idem as above (line27)
line 31: j<15, only the first 15 char of every word are shifted
0
Angelo Oh really? Like what mistakes? Thanks btw
0
CarrieForle thanks! 🙏
0
Angelo thanks for the feedback! (I'm not sure if I said right, English isn't my main language 😅)