0
[Answered] My code does not pass 2 of the 3 locked test cases (Code Coach "Average Word Length")
As mentioned in my title, my code that I have written does not pass all test cases in the Code Coach and I don't have any idea why, because only locked test cases are failed. I have tried many things, and from testing I found that the word count, letter count and average word length count are correct, after ceiling them too. My code here: https://code.sololearn.com/czOhwSvs916t/?ref=app Code Coach Challenge here: https://www.sololearn.com/coach/73?ref=app
12 ответов
+ 3
😂 BeginEnd
You solution passes all test cases ✔️
But " count / num + 1 " is complete wrong!
Try it out. Input: "abc abc abc"
It becomes 4 😮
But I'm sure, it must be 3
It would be better, you're using Math.ceiling() instead of add one.
+ 1
Here are some points:
1. One word input throws an exception.
2. Two word input for example "x xx" becomes 1, expected is 2.
3. Don't invend the wheel new. Simple use Math.Ceiling()
0
Coding Cat [Mouse searching] I have changed my code now and only the fifth case fails now. Your points helped a lot. But I still can't figure out why the last case fails. You can (hopefully) see my updated code at the same link.
I always forget about Math.Ceiling because Math.Floor isn't named Math.Flooring and in Sketchware (Android app) Ceil was valid
0
C4Oc wenn dein Profil korrekt ist, solltest du mich auch so verstehen?
0
Coding Cat [Mouse searching] Ja, das ist richtig
0
Ok, irgend etwas passt noch nicht. Ich habe mal das Beispiel eingegeben :
Sample Input:
this phrase has multiple words
Sample Output:
6
Bekomme aber 5 als Resultat.
Mir erscheint das auch als zu viel Code. Habe aber selbst ewig lange nichts mehr in C# gemacht.
0
Ich würde folgendes versuchen:
1. Kompletten Input mit
char. IsLetter() durchsuchen und Buchstaben zählen.
2. Mit input.Split(' ') die Wörter in einer Liste speichern und anschließend zählen (Länge d. Liste)
3. Wie gehabt teilen und ceilen.
0
Coding Cat [Mouse searching] Vielen Dank für deine Hilfe. Ich habe es jetzt geschafft und es funktioniert jetzt wie gewollt, also habe ich jetzt alle 5 Fälle bestanden.
Ich werde auch deine Vorschläge ausprobieren
0
Super 👍
Und bitte, gern geschehen 🙋♂️
0
Ich hab' meine Vorschläge hier mal ausprobiert. Vom Prinzip her geht das also.
https://code.sololearn.com/cPUY0eAoVaP6/?ref=app
0
Average Word code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string[] n = s.Split(' ');
int count = 0;
int num = n.Length;
for (int i = 0; i < num; i++)
{
string str = n[i];
for(int j = 0; j < str.Length ; j++)
{
if (char.IsPunctuation (str[j]))
{
str = str.Remove(j,1);
count -= 1;
}
}
count += str.Length;
}
Console.Write((count/ num) + 1);
}
}
}
0
BeginEnd Thank you for giving me this even simpler solution. I used a solution without x.Split() originally and that's the one that I was able to get working