MartisK

KD 2. Tekstas

Jan 8th, 2021 (edited)
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Program
  5. {
  6.     public class Program
  7.     {
  8.         // nezinau ar reikia pasikartojancius simbolius skaiciuot ar ne, bet speju, kad nereikia, tai padariau lista, i kuri dedami rasti simboliai
  9.         public static int NumberOfSymbols(string line, string s)
  10.         {
  11.             int result = 0;
  12.             List<char> foundSymbols = new List<char>();
  13.  
  14.             if (!String.IsNullOrEmpty(line) && !String.IsNullOrEmpty(s))
  15.             {
  16.                 for(int i = 0; i < line.Length; i++)
  17.                 {
  18.                     if (!foundSymbols.Contains(line[i]) && s.Contains(line[i].ToString()))
  19.                     {
  20.                         result ++;
  21.                         foundSymbols.Add(line[i]);
  22.                     }
  23.                 }
  24.             }
  25.  
  26.             return result;
  27.         }
  28.    
  29.         // nesumaisyk return true ir return false vietomis
  30.         public static bool MoreVowels(string line)
  31.         {
  32.             string vowelLetters = "aąeęėiįyouųū";
  33.             string consonantLetters = "bcčdfghjklmnprsštvzž";
  34.             int vowelCount = 0;
  35.             int consonantCount = 0;
  36.  
  37.             for (int i = 0; i < line.Length; i++)
  38.             {
  39.                 if (vowelLetters.Contains(line[i].ToString().ToLower()))
  40.                 {
  41.                     vowelCount ++;
  42.                 }
  43.                 if (consonantLetters.Contains(line[i].ToString().ToLower()))
  44.                 {
  45.                     consonantCount ++;
  46.                 }
  47.             }
  48.  
  49.             if (consonantCount >= vowelCount )
  50.             {
  51.                 return false;
  52.             }
  53.  
  54.             return true;
  55.         }
  56.  
  57.         public static string FindWord1InLine(string line, string punctuation)
  58.         {
  59.             string resultingWord = "";
  60.             string[] words = line.Split(punctuation.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  61.             string[] puncArray = line.Split(words, StringSplitOptions.RemoveEmptyEntries);
  62.  
  63.             for (int i = 0; i < words.Length; i++)
  64.             {
  65.                 if (MoreVowels(words[i]))
  66.                 {
  67.                     resultingWord = words[i];
  68.  
  69.                     if (i < puncArray.Length)
  70.                     {
  71.                         resultingWord += puncArray[i];
  72.                     }
  73.  
  74.                     break;
  75.                 }
  76.             }
  77.             return resultingWord;
  78.         }
  79.  
  80.         public static string FindWord2InLine(string line, string punctuation)
  81.         {
  82.             string resultingWord = "";
  83.             string[] words = line.Split(punctuation.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  84.             string[] puncArray = line.Split(words, StringSplitOptions.RemoveEmptyEntries);
  85.             int maxLength = 0;
  86.  
  87.             for (int i = 0; i < words.Length; i++)
  88.             {
  89.                 if (MoreVowels(words[i]) && words[i].Length > maxLength)
  90.                 {
  91.                     maxLength = words[i].Length;
  92.                     resultingWord = words[i];
  93.  
  94.                     if (i < puncArray.Length)
  95.                     {
  96.                         resultingWord += puncArray[i];
  97.                     }
  98.                 }
  99.             }
  100.             return resultingWord;
  101.         }
  102.  
  103.         // su situ editu yra vienas flaw, kuri zinau, bet nera laiko sutvarkyt, kai baigsi parasyk, paaiskinsiu kas per klaida :D gal destytojai patys nesugalvos patikrinti tokio varianto, kuriuo neveiktu pilnai teisingai
  104.         public static string EditLine(string line, string punctuation, string word)
  105.         {
  106.             string[] words = line.Split(punctuation.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  107.             string[] puncArray = line.Split(words, StringSplitOptions.RemoveEmptyEntries);
  108.  
  109.             if (!String.IsNullOrEmpty(word))
  110.             {
  111.                 string newLine = "";
  112.  
  113.                 for (int i = 0; i < words.Length; i++)
  114.                 {
  115.                     if (i < puncArray.Length)
  116.                     {
  117.                         words[i] += puncArray[i];
  118.                     }
  119.  
  120.                     if (String.Compare(word, words[i]) == 0)
  121.                     {
  122.                         newLine = word;
  123.                         newLine += line.Replace(newLine, "");
  124.                         break;
  125.                     }
  126.                 }
  127.                 return newLine;
  128.             }
  129.  
  130.             return line;
  131.         }
  132.  
  133.         public static void PerformTasksN(string fd, string fr)
  134.         {
  135.             string punctuation = null;
  136.             string[] lines = null;
  137.  
  138.             // read 'punctuation' and 'lines' from file here...
  139.  
  140.             int movedWordsCount = 0;
  141.             List<string> movedWords = new List<string>();
  142.  
  143.             foreach(string line in lines)
  144.             {
  145.                 string word = FindWord1InLine(line, punctuation);
  146.                 string wordWithoutPunctuation = word.Split(punctuation.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  147.                 movedWords.Add(wordWithoutPunctuation[0]);
  148.                 string editedLine = EditLine(line, punctuation, word);
  149.                 // write 'editedLine' to file here...
  150.  
  151.                 if (!String.IsNullOrEmpty(word))
  152.                 {
  153.                     movedWordsCount ++;
  154.                 }
  155.  
  156.                 string word2 = FindWord2InLine(line, punctuation);
  157.                 string word2WithoutPunctuation = word2.Split(punctuation.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  158.                 movedWords.Add(word2WithoutPunctuation[0]);
  159.                 editedLine = EditLine(line, punctuation, word2);
  160.                 // write 'editedLine' to file here...
  161.  
  162.                 if (!String.IsNullOrEmpty(word2))
  163.                 {
  164.                     movedWordsCount ++;
  165.                 }
  166.             }
  167.  
  168.             foreach(string word in movedWords)
  169.             {
  170.                 // write 'word' to file here...
  171.             }
  172.  
  173.             // write 'movedWordsCount' to file here...
  174.         }
  175.     }
  176. }
Add Comment
Please, Sign In to add comment