0
(solved)Help me with string functioning in C. Thank you already🤗
I have this code, which gets a sentence as input and outputs the same sentence but with all the numbers>0 and <=10 written in their word formats. But for some reason, I'm not getting the correct input, but somehow relevant one. Please help me. Thank you https://code.sololearn.com/cwcGQYJI8g30/?ref=app Edit:upgraded code(only timeout problem): https://code.sololearn.com/cdgEw7Gol1Ie/?ref=app
12 Respuestas
+ 2
Ipang finally got the answer. Passed all the test cases
https://code.sololearn.com/c0L41kuZ1vI9/?ref=app
+ 2
Rishi,
Good job 👍
+ 1
you forgot the name of the strtok function in the increment section of the for loop. However, there are some other problems
+ 1
Rishi,
Is this about the "No numerals" code coach? I had to ask, cause I don't see 10 being replaced by "ten" in your code.
What input is needed to test?
+ 1
Ipang yes exactly. 😲 Yes I forgot to include that. I'll add that. By the way, if you found a way to change 0 to "zero", please tell me
+ 1
Rishi,
I have tried it, but my code wouldn't pass the coach test cause I added some things I had in mind back then.
But you can check it to get some idea. BTW my code prints output directly, while your code writes to a string buffer which is printed once work is done.
https://code.sololearn.com/cd7q4byR9cD6/?ref=app
+ 1
Ipang but there's one minor problem, it should print 55 as 55 only but your code prints it as five five. That's why I abandoned my code which used character by character. The code coach said that your code didn't pass a test case which is hidden?
0
Ciro Pellegrino after that, it works somehow relevant but not the exact answer. Just some minor errors. Run it and see now. Is my code worth working or I have to let it go? If it's worth, please help me. Thank you
0
Ciro Pellegrino see my new code
https://code.sololearn.com/cdgEw7Gol1Ie/?ref=app
It works correctly but except for changing 0 to "zero". In the part I try to do that, I'm getting timeout error and I don't know why. Please help me. Thank you.
0
/*I didn't realize it was a code coach exercise. I solved it like this*/
#include <stdio.h>
int main() {
char s[100];
while(scanf("%s",s)!=EOF){
if(s[0]=='0' && strlen(s)==1){
printf("zero ");
continue;
}
switch(atoi(s)){
case 1:printf("one ");break;
case 2:printf("two ");break;
case 3:printf("three ");break;
case 4:printf("four ");break;
case 5:printf("five ");break;
case 6:printf("six ");break;
case 7:printf("seven ");break;
case 8:printf("eight ");break;
case 9:printf("nine ");break;
case 10:printf("ten ");break;
default:
printf("%s ",s);
}
}
return 0;
}
0
Ciro Pellegrino it's so simple😲, I just came to know that we can take string inputs like this too
- 1
Wate