This commit is contained in:
Софья Островская 2023-10-17 10:35:30 +04:00
parent c680a6e51d
commit 685fd6ab9b
3 changed files with 6 additions and 31 deletions

View File

@ -1,5 +0,0 @@
{
"version": 1,
"isRoot": true,
"tools": {}
}

View File

@ -2,11 +2,11 @@
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
var dir = new DirectoryInfo("../var/data"); var dir = new DirectoryInfo("/var/data");
var files = dir.GetFiles(); var files = dir.GetFiles();
string resultFilePath = "../var/result/data.txt"; string resultFilePath = "/var/result/data.txt";
try try
{ {
int[] mass = new int[files.Length]; int[] mass = new int[files.Length];

View File

@ -1,32 +1,12 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
string[] lines = File.ReadAllLines("../var/data/data.txt"); string[] lines = File.ReadAllLines("/var/data/data.txt");
int firstNumber = 0; int multiplication = Convert.ToInt32(lines.First()) * Convert.ToInt32(lines.Last());
int lastNumber = 0;
foreach (string line in lines) using (StreamWriter writer = new StreamWriter("/var/result/result.txt"))
{
if (int.TryParse(line, out int number))
{
firstNumber = number;
break;
}
}
for (int i = lines.Length - 1; i >= 0; i--)
{
if (int.TryParse(lines[i], out int number))
{
lastNumber = number;
break;
}
}
int multiplication = firstNumber * lastNumber;
using (StreamWriter writer = new StreamWriter("../var/result/result.txt"))
{ {
writer.WriteLine(multiplication); writer.WriteLine(multiplication);
} }