+ 3

problem solving

there are some problems in solo learn to complete easy,, but i have some problems see this problem👇 You write a phrase and include a lot of number characters (0-9), but you decide that for numbers 10 and under you would rather write the word out instead. Can you go in and edit your phrase to write out the name of each number instead of using the numeral? how i can get strings that sololearn problem automatically give to test my code??.i write my algorithm and works perfect, the problem is how to get the test phrases of solo🙄🤔 pls help me,😤😤😤

7th Mar 2020, 1:17 PM
Ali Najafian
Ali Najafian - avatar
21 Respuestas
+ 3
Just do it as if you are taking input from the user. For example in cin(in C++),input()(in python),scanf()(in C)
7th Mar 2020, 1:20 PM
Arsenic
Arsenic - avatar
+ 2
no, problem is that, user wont enter the phrase, the sololearn has 6 test case, that they are fix each test case has one input!!!
7th Mar 2020, 1:25 PM
Ali Najafian
Ali Najafian - avatar
+ 2
Ali Najafian you can consider sololearn as a person who is going to run your program 5 times and input an phrase as input everytime
7th Mar 2020, 1:28 PM
Arsenic
Arsenic - avatar
+ 2
Is it test case 3 ?
7th Mar 2020, 1:35 PM
Arsenic
Arsenic - avatar
+ 2
import string def solve(s): for ch in s: if ch == '1': print("one", end = '') elif ch == '2': print("two", end = '') elif ch =='3': print("three", end = '') elif ch == '4': print('four', end = '') elif ch == '5': print('five',end = '') elif ch == '6': print( 'six', end = '') elif ch == '7': print('seven', end = '') elif ch == '8': print('eight', end = '') elif ch == '9': print('nine', end = '') elif ch == '0': print('zero', end = '') elif ch == '10': print('ten', end ='') else: print(ch , end='') s=input() solve(s)
7th Mar 2020, 1:42 PM
Ali Najafian
Ali Najafian - avatar
+ 1
thnaks, solved!! but one test case failde!!🤔 and it is locked i can not see result, how i can solve and debuge that, any idea?
7th Mar 2020, 1:33 PM
Ali Najafian
Ali Najafian - avatar
+ 1
yes
7th Mar 2020, 1:37 PM
Ali Najafian
Ali Najafian - avatar
+ 1
It must be because your program is not converting 10 to "ten"
7th Mar 2020, 1:37 PM
Arsenic
Arsenic - avatar
+ 1
Share your code here
7th Mar 2020, 1:39 PM
Arsenic
Arsenic - avatar
+ 1
i think problem is 10 my code mistake🤪
7th Mar 2020, 1:41 PM
Ali Najafian
Ali Najafian - avatar
+ 1
ch =='10' is wrong phrase!🙈😀
7th Mar 2020, 1:43 PM
Ali Najafian
Ali Najafian - avatar
7th Mar 2020, 1:55 PM
Arsenic
Arsenic - avatar
+ 1
thanks
7th Mar 2020, 1:57 PM
Ali Najafian
Ali Najafian - avatar
+ 1
my code was so bad what's your idea? i think i could write it using 2 nested iteration through a dictionary and input steing, and solve that faster, is it faster or first one?
7th Mar 2020, 1:59 PM
Ali Najafian
Ali Najafian - avatar
+ 1
Continuation: else if(str.at(i) == '7'){ str.erase(i,1); str.insert(i,"seven"); } else if(str.at(i) == '8'){ str.erase(i,1); str.insert(i,"eight"); } else if(str[i] == '9'){ str.erase(i,1); str.insert(i,"nine"); } } bool isReplaced = ReplaceString(str,"onezero","ten"); if(isReplaced){ cout<<str; } else{ cout<<str; } } bool ReplaceString(string &s, const string &oldSubstr, const string &newSubstr){ bool isReplaced = false; int currentPosition = 0; while(currentPosition < s.length()){ int position = s.find(oldSubstr, currentPosition); if(position == string::npos){ return isReplaced; } else{ s.replace(position,oldSubstr.length(),newSubstr); currentPosition = position + newSubstr.length(); isReplaced = true; } } return isReplaced; }
22nd Jul 2021, 11:26 AM
Ian Edwin Kaire
Ian Edwin Kaire - avatar
0
yes, i did it, but didn't passed
7th Mar 2020, 1:38 PM
Ali Najafian
Ali Najafian - avatar
0
no idea🙄🙃🤔
7th Mar 2020, 1:44 PM
Ali Najafian
Ali Najafian - avatar
0
Here's my code in Java I used String and StringBuilder class to display the output Scanner s = new Scanner(System.in); System.out.print("Input: "); String strn = s.nextLine(); StringBuilder str = new StringBuilder(strn); for(int i = 0; i < str.length(); i++){ if(str.charAt(i) == '0'){ str.deleteCharAt(i); str.insert(i,"zero"); } else if(str.charAt(i) == '1'){ str.deleteCharAt(i); str.insert(i,"one"); } else if(str.charAt(i) == '2'){ str.deleteCharAt(i); str.insert(i,"two"); } else if(str.charAt(i) == '3'){ str.deleteCharAt(i); str.insert(i,"three"); } else if(str.charAt(i) == '4'){ str.deleteCharAt(i); str.insert(i,"four"); } else if(str.charAt(i) == '5'){ str.deleteCharAt(i); str.insert(i,"five"); } else if(str.charAt(i) == '6'){ str.deleteCharAt(i); str.insert(i,"six"); }
22nd Jul 2021, 11:20 AM
Ian Edwin Kaire
Ian Edwin Kaire - avatar
0
Here's the continuation: else if(str.charAt(i) == '7'){ str.deleteCharAt(i); str.insert(i,"seven"); } else if(str.charAt(i) == '8'){ str.deleteCharAt(i); str.insert(i,"eight"); } else if(str.charAt(i) == '9'){ str.deleteCharAt(i); str.insert(i,"nine"); } } String st = str.toString(); if(st.contains("onezero")){ System.out.print(st.replaceAll("onezero","ten")); } else{ System.out.print(st); }
22nd Jul 2021, 11:21 AM
Ian Edwin Kaire
Ian Edwin Kaire - avatar
0
Here's my code in C++: #include <iostream> #include <string> using namespace std; bool ReplaceString(string &s, const string &oldSubstr, const string &newSubstr); int main(){ cout<<"Input: "; string str; getline(cin,str); for(int i = 0; i < str.length(); i++){ if(str[i] == '0'){ str.erase(i,1); str.insert(i,"zero"); } else if(str[i] == '1'){ str.erase(i,1); str.insert(i,"one"); } else if(str[i] == '2'){ str.erase(i,1); str.insert(i,"two"); } else if(str[i] == '3'){ str.erase(i,1); str.insert(i,"three"); } else if(str.at(i) == '4'){ str.erase(i,1); str.insert(i,"four"); } else if(str.at(i) == '5'){ str.erase(i,1); str.insert(i,"five"); } else if(str.at(i) == '6'){ str.erase(i,1); str.insert(i,"six"); }
22nd Jul 2021, 11:25 AM
Ian Edwin Kaire
Ian Edwin Kaire - avatar