Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace RecursiveOperatorsCombinations
- {
- public class Program
- {
- public static void Main()
- {
- int intLength = int.Parse(Console.ReadLine());
- int targetValue = int.Parse(Console.ReadLine());
- if (PrintValidSolutions(intLength, targetValue, " = " + targetValue))
- {
- return;
- }
- Console.WriteLine("N/A");
- }
- private static bool PrintValidSolutions(int intLength, int targetValue, string currentString)
- {
- if (intLength == 1)
- {
- if (targetValue == 1)
- {
- Console.Write("1" + currentString + "\n");
- return true;
- }
- return false;
- }
- bool found = PrintValidSolutions(intLength - 1, targetValue + intLength, " - " + intLength + currentString);
- if (PrintValidSolutions(intLength - 1, targetValue - intLength, " + " + intLength + currentString))
- {
- found = true;
- }
- return found;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement