Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Equal_Sums_Left_Right_Position
- {
- class Program
- {
- static void Main(string[] args)
- {
- int a = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- int sumLeft = 0;
- int sumRight = 0;
- int sumMiddle = 0;
- int sumAdd = 0;
- for (int i = a; i <= b; i++)
- {
- string iToString = i.ToString();
- for (int j = 0; j < iToString.Length; j++)
- {
- char num = iToString[j];
- int numInt = int.Parse(num.ToString());
- int position = j + 1;
- if (position == 1 || position == 2)
- {
- sumLeft += numInt;
- }
- if (position == 4 || position == 5)
- {
- sumRight += numInt;
- }
- if (position == 3)
- {
- sumMiddle = numInt;
- }
- }
- if (sumLeft == sumRight)
- {
- Console.Write(iToString + " ");
- }
- if (sumLeft > sumRight)
- {
- sumAdd = sumRight + sumMiddle;
- if (sumLeft == sumAdd)
- {
- Console.Write(iToString + " ");
- }
- }
- else if (sumLeft < sumRight)
- {
- sumAdd = sumLeft + sumMiddle;
- if (sumRight == sumAdd)
- {
- Console.Write(iToString + " ");
- }
- }
- sumLeft = 0;
- sumRight = 0;
- sumMiddle = 0;
- sumAdd = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement