Advertisement
OIQ

Untitled

OIQ
Oct 7th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. partial class Program
  5. {
  6.     private static string GetTextFromFile(string inputPath)
  7.     {
  8.         string data = "";
  9.         try {
  10.             using (StreamReader sr = new StreamReader("input.txt")) {
  11.                 string line;
  12.                 while ((line = sr.ReadLine()) != null)
  13.                     data += line;
  14.             }
  15.         }
  16.         catch (Exception e) {
  17.             Console.WriteLine(e.Message);
  18.         }
  19.  
  20.         return data;
  21.  
  22.     }
  23.  
  24.     private static int GetSumFromText(string text)
  25.     {
  26.         int res = 0;
  27.         text = text.ToLower();
  28.         string number = "";
  29.         bool flag = false;
  30.         for (int i = 0; i < text.Length; i++) {
  31.             if (text[i] == '-' || (text[i] >= '0' && text[i] <= '9') || (text[i] >= 'a' && text[i] <= 'z')) {
  32.                 number += text[i++];
  33.                 while (i < text.Length && ((text[i] >= '0' && text[i] <= '9') || (text[i] >= 'a' && text[i] <= 'z')))
  34.                     number += text[i++];
  35.                 if (int.TryParse(number, out int curr))
  36.                     res += curr;
  37.                 number = "";
  38.             }
  39.         }
  40.  
  41.         if (int.TryParse(number, out int curr1))
  42.             res += curr1;
  43.  
  44.         return res;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement