0

Help with Pig Latin

#include <iostream> using namespace std; int main() { string a,b,c,aa,bb,cc; cin>>a>>b>>c; aa=a; bb=b; cc=c; string s="ay"; a.erase(a.begin()); b.erase(b.begin()); c.erase(c.begin()); a.insert(a.end(),aa[0]); b.insert(b.end(),bb[0]); c.insert(c.end(),cc[0]); a.append(s); b.append(s); c.append(s); cout<<a<<" "<<b<<" "<<c; return 0; } Why aren'ttwo test cases exact?

11th Jun 2021, 2:34 PM
Francesco Famosi
Francesco Famosi - avatar
2 odpowiedzi
+ 5
Pig Latin answer 👇 #include <iostream> using namespace std; void change(string x) { int i; i=x.size(); if(i>0) { string ch=x; x.erase(0,1); cout<<x<<ch[0]<<"ay"; } } int main() { string a[1000]; for(int i=0;i<1000;i++) { cin>>a[i]; change(a[i]); cout<<" "; } return 0; }
11th Jun 2021, 2:44 PM
Tharul Nejana
Tharul Nejana - avatar
+ 2
Francesco Famosi it doesn't said that the sentence contains only 3 words. You should use : getline(cin,str); To input a line instead of a word Then you should recognize the words by the space between them.
11th Jun 2021, 2:48 PM
Mani_K_A