+ 1

Jungle Camping problem

Only 4/5 tests are correct // #include <iostream> #include <string> using namespace std; int main() { int i; string a,b,c,d,sounds[99]; a="Grr"; b="Rawr"; c="Ssss"; d="Chirp"; cin>>sounds[0]; cin>>sounds[1]; cin>>sounds[2]; cin>>sounds[3]; for (i=0;i<4;i++) { if (sounds[i]==a) cout<<"Lion "; if (sounds[i]==b) cout<<"Tiger "; if (sounds[i]==c) cout<<"Snake "; if (sounds[i]==d) cout<<"Bird "; } return 0; }

20th Apr 2020, 9:57 PM
Eskalate
Eskalate - avatar
8 Answers
+ 1
The input can be more than 4 sounds.
20th Apr 2020, 10:01 PM
Dennis
Dennis - avatar
+ 1
Well, yeah, it's not just the cins. The input can be anywhere between 0 and a theoretically infinite number. You're not handling that correctly. But it's a puzzle, I can't help too much. :)
20th Apr 2020, 10:11 PM
Dennis
Dennis - avatar
+ 1
#include<iostream> #include<string> using namespace std; main(){ string s; getline(cin,s); while(s.find("Grr")!=-1){ int a; a=s.find("Grr"); s.replace(a,3,"Lion"); } while(s.find("Rawr")!=-1){ int a; a=s.find("Rawr"); s.replace(a,4,"Tiger"); } while(s.find("Ssss")!=-1){ int a; a=s.find("Ssss"); s.replace(a,4,"Snake"); } while(s.find("Chirp")!=-1){ int a; a=s.find("Chirp"); s.replace(a,5,"Bird"); } cout<<s; }
29th Aug 2020, 4:34 AM
namrata singh
namrata singh - avatar
+ 1
namrata singh I like your solution with how it handles multiple sounds of the same kind, I had to change the -1's to string::npos for it to compile
11th Dec 2021, 12:07 PM
boneSpider
boneSpider - avatar
0
It's the cin's right?
20th Apr 2020, 10:02 PM
Eskalate
Eskalate - avatar
0
Yes
20th Apr 2020, 10:05 PM
Dennis
Dennis - avatar
0
It's still don't pass 5th test
20th Apr 2020, 10:07 PM
Eskalate
Eskalate - avatar
0
Thx
20th Apr 2020, 10:12 PM
Eskalate
Eskalate - avatar