[Programming Fundamentals] Exam 30.04.2017 - Задача 2
Минават нулевите тестове. Не дава повече от 40т. код
Минават нулевите тестове. Не дава повече от 40т. код
Къде проверяваш The sentences will ALWAYS start with a capital letter?
Здравей. Това което откривам на пръв поглед е че например когато имаш запетая в изречение, то тя се взима към текущата дума и ако преди нея има дума с повтаряща се буква то дължината ѝ се променя съответно:
Input: This is a random sentence, and this is another sentence.
Output: This is a random eeeeeeeee and this is another eeeeeeee.
Помисли върху това. Препоръчвам ти да ползваш решение с regex.
Благодаря за напътствията !
Оправих бъга и вече ми даде 100/100..)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace _02.Worm_Ipsum
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputLine = Console.ReadLine();
           var result = new List<string>();
            while (inputLine != "Worm Ipsum")
            {
                var line = inputLine.Split(new[] {'.'},StringSplitOptions.RemoveEmptyEntries);
             
                if (line.Length==1)
                {
                    var lineValid = inputLine.Split(new[] {' ','.'}, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var word in lineValid)
                    {
                       
                        var curentWord = "";
                        char curentChar;
                        var maxCounter = 0;
                        for (int i = 0; i < word.Length; i++)
                        {
                           
                            var counter = 0;
                            var index = word.IndexOf(word[i]);
                            while (index !=-1)
                            {
                                counter++;
                                index = word.IndexOf(word[i], index + 1);
                            }
                            if (counter>=2 && maxCounter < counter)
                            {
                                curentWord = string.Empty;
                                curentChar = word[i];
                                 maxCounter = counter;
                                if (word.IndexOf(",")== -1)
                                {
                                    for (int j = 0; j < word.Length; j++)
                                    {
                                        curentWord += curentChar;
                                    }
                                }
                                else
                                {
                                    for (int j = 0; j < word.Length-1; j++)
                                    {
                                        curentWord += curentChar;
                                    }
                                    curentWord += ",";
                                }
                               
                             
                            }
                           
                        }
                        if (curentWord !="")
                        {
                            result.Add(curentWord);
                        }
                        else
                        {
                            result.Add(word);
                        }
                       
                    }
                    Console.WriteLine(string.Join(" ",result)+".");
                }
                result.Clear();
                inputLine = Console.ReadLine();
            }
           
        }
       
    }
}
Супер. Чисто информативно слагам две решения с regex при интерес. Едното е близко до твоето.
https://dotnetfiddle.net/oXQZds - регекс + сравняване на всеки символ (по-близко до твоето)
https://github.com/stefkavasileva/SoftUni-Software-Engineering/blob/master/Programmin%20Fundamentals/OldExams/RetakeExam-30-April-2017/02.WormIpsum/WormIpsum.cs - предимно regex и LINQ
Пише,че изреченията ще са граматически правилни.