Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- partial class Program
- {
- private static string GetTextFromFile(string inputPath)
- {
- string data = "";
- try {
- using (StreamReader sr = new StreamReader("input.txt")) {
- string line;
- while ((line = sr.ReadLine()) != null)
- data += line;
- }
- }
- catch (Exception e) {
- Console.WriteLine(e.Message);
- }
- return data;
- }
- private static int GetSumFromText(string text)
- {
- int res = 0;
- text = text.ToLower();
- string number = "";
- bool flag = false;
- for (int i = 0; i < text.Length; i++) {
- if (text[i] == '-' || (text[i] >= '0' && text[i] <= '9') || (text[i] >= 'a' && text[i] <= 'z')) {
- number += text[i++];
- while (i < text.Length && ((text[i] >= '0' && text[i] <= '9') || (text[i] >= 'a' && text[i] <= 'z')))
- number += text[i++];
- if (int.TryParse(number, out int curr))
- res += curr;
- number = "";
- }
- }
- if (int.TryParse(number, out int curr1))
- res += curr1;
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement