Problem in code coach problem....No Numeral | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem in code coach problem....No Numeral

I am stuck in it for 2 days almost but couldn't figure out the ambiguity 😔😔. #include <iostream> #include <string> #include <vector> #include <cctype> using namespace std; int main() { vector<string> words{ "zero","one","two","three", "four","five","six","seven", "eight","nine","ten" }; vector<char> result{}; string sentence{}; getline(cin, sentence ); for(size_t i{0};i<sentence.length();i++){ if(isdigit(sentence[i]) && !(isdigit(sentence[i+1]))){ int n=sentence[i]-'0'; for(size_t j{0};j<words[n].length();j++){ result.push_back(words[n][j]); } }else if(isalpha(sentence[i]) || isspace(sentence[i])){ result.push_back(sentence[i]); }else if(sentence[i]=='1' && sentence[i+1]=='0'){ for(size_t k{0};k<3;k++){ result.push_back(words[10][k]); } } } for(char c: result ) cout<<c; cout<<endl; return 0; }

31st May 2021, 6:38 AM
saurabh
saurabh - avatar
3 Answers
+ 2
When replacing the word ten, you translate two digits at once instead of one, so you need to update your loop index accordingly.
31st May 2021, 7:00 AM
Shadow
Shadow - avatar
+ 1
Shadow ohhh shit😬 Got it....👍 Thanks bro........
31st May 2021, 7:14 AM
saurabh
saurabh - avatar
0
5/6 passed.... 3rd not passed
31st May 2021, 6:40 AM
saurabh
saurabh - avatar