+ 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; }
8 Antworten
+ 1
The input can be more than 4 sounds.
+ 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. :)
+ 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;
}
+ 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
0
It's the cin's right?
0
Yes
0
It's still don't pass 5th test
0
Thx