Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace _01._EvenLines
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string filePath = @"C:\Users\I353529\Desktop\Streams_Resources\text.txt";
- //1. прочетем четните редовете
- //2. заменим символите с @
- //3. reverse words
- using (StreamReader reader = new StreamReader(filePath))
- {
- int counter = -1; //брой редовете
- string line = reader.ReadLine(); //четем по 1 ред от файла
- while (line != null)
- {
- counter++;
- if (counter % 2 == 0)
- {
- //замяна
- line = Replace(line);
- //обърна в обратен ред
- line = Reverse(line);
- Console.WriteLine(line);
- }
- line = reader.ReadLine();
- }
- }
- }
- private static string Reverse(string line)
- { //"@I was quick to judge him@ but it wasn't his fault@".Split()
- //["@I", "was", "quick", "to", "judge", "him@", "but", "it", "wasn't", "his", "fault@"].Reverse()
- //["fault@", "his", "wasn't", "it", "but", "him@", "judge", "to", "quick", "was", "@I"].Join(" ")
- //"fault@ his wasn't it but him@ judge to quick was @I"
- return string.Join(" ", line.Split().Reverse());
- }
- private static string Replace(string line) //върне реда със заместени символи
- {
- //-I was quick to judge him, but it wasn't his fault.
- //@I was quick to judge him@ but it wasn't his fault@
- return line.Replace("-", "@")
- .Replace(",", "@")
- .Replace(".", "@")
- .Replace("!", "@")
- .Replace("?", "@");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement