Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int result1 = 0;
- int result2 = 0;
- string[] inputArray = File.ReadAllLines(@"input.txt");
- for (int i = 0; i < inputArray.Length; i++)
- {
- if (inputArray[i].Substring(0, 1) == "+")
- {
- result1 += Convert.ToInt32(inputArray[i].Remove(0, 1));
- }
- if (inputArray[i].Substring(0, 1) == "-")
- {
- result1 -= Convert.ToInt32(inputArray[i].Remove(0, 1));
- }
- }
- Console.WriteLine(result1);
- bool found = true;
- List<int> freqs = new List<int>();
- while (found)
- {
- for (int i = 0; i < inputArray.Length; i++) {
- if (inputArray[i].Substring(0, 1) == "+") {
- result2 += Convert.ToInt32(inputArray[i].Remove(0, 1));
- }
- if (inputArray[i].Substring(0, 1) == "-") {
- result2 -= Convert.ToInt32(inputArray[i].Remove(0, 1));
- }
- if (freqs.Contains(result2)) { found = false; break; }
- freqs.Add(result2);
- }
- }
- Console.WriteLine(result2);
- File.Create("output.txt").Dispose();
- using (TextWriter tw = new StreamWriter("output.txt")) {
- tw.WriteLine(result1);
- tw.WriteLine(result2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement