Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5.  
  6. namespace ConsoleApplication1{
  7.     class Program{
  8.         static void Main(string[] args){
  9.             Console.WriteLine("Írj be 1 szót");
  10.             string read = Console.ReadLine().ToLower();
  11.        
  12.             if(read.Contains('a') || read.Contains('e') || read.Contains('i') || read.Contains('o') || read.Contains('u')) {
  13.                 Console.WriteLine("Van benne magánhangzó");
  14.             }else{
  15.                 Console.WriteLine("Nincs benne magánhangzó");
  16.             }
  17.        
  18.             List<string> otbetus = new List<string>();
  19.             string longest = "";
  20.             int wordCounter = 0, lineCounter = 0;
  21.             using(StreamReader input = new StreamReader("szoveg.txt")){
  22.                 for(string line = input.ReadLine(); line != null; line = input.ReadLine(), ++lineCounter) {
  23.                     int lineLenght = line.Length;
  24.                     if(lineLenght > longest.Length) {
  25.                         longest = line;
  26.                     }
  27.                     if(lineLenght == 5) {
  28.                         otbetus.Add(line);
  29.                     }
  30.                     int mghCounter = 0;
  31.                     for(int k = 0; k < lineLenght; ++k) {
  32.                         char temp = line[k];
  33.                         if(temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u') {
  34.                             ++mghCounter;
  35.                         }
  36.                     }
  37.                     if(lineLenght / 2 < mghCounter) {
  38.                         ++wordCounter;
  39.                         Console.Write(line + " ");
  40.                     }
  41.                 }
  42.             }
  43.        
  44.             Console.WriteLine();
  45.             Console.WriteLine("A leghoszabb szó: " + longest + ", hossza: " + longest.Length);
  46.             Console.WriteLine("Mgh-s szavak száma: " + wordCounter);
  47.             Console.WriteLine("Összes szó: " + lineCounter);
  48.             Console.WriteLine(wordCounter + "/" + lineCounter + ", ez százalékban {0}%\n", ((float)wordCounter / lineCounter * 100).ToString("0.00"));
  49.        
  50.             Console.WriteLine("Írj be 1 szórészletet");
  51.             string meh = Console.ReadLine();
  52.             foreach(string check in otbetus) {
  53.                 if(check.Contains(meh)) {
  54.                     Console.Write(check + " ");
  55.                 }
  56.             }
  57.             Console.WriteLine();
  58.        
  59.             using(StreamWriter output = new StreamWriter("letra.txt")){
  60.                 List<string> used = new List<string>();
  61.                 List<string> buffer = new List<string>();
  62.                 foreach(string check in otbetus) {
  63.                     string threeLetters = check.Substring(1, 4);
  64.                     if(!used.Contains(threeLetters)) {
  65.                         used.Add(threeLetters);
  66.                         foreach(string sajt in otbetus) {
  67.                             string trimmed = sajt.Substring(1, 4);
  68.                             if(trimmed.Equals(threeLetters)) {
  69.                                 buffer.Add(sajt);
  70.                             }
  71.                         }
  72.                         if(buffer.Count > 1) {
  73.                             foreach(string print in buffer) {
  74.                                 output.WriteLine(print);
  75.                             }
  76.                             output.WriteLine();
  77.                         }
  78.                         buffer.Clear();
  79.                     }
  80.                 }
  81.             }
  82.             Console.WriteLine("Press enter to exit...");
  83.             Console.Read();
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement