📜  给定(A + B),(A + C)和(B + C)中的两个时求A,B和C的最小可能值

📅  最后修改于: 2021-04-28 18:38:39             🧑  作者: Mango

给定两个整数XY。 XY表示(A + B),(A + C)和(B + C)中的任何两个值。任务是找到ABC ,使得A + B + C最小可能。
例子:

方法:X = A + BY = B + C。如果X> Y,让我们交换它们。请注意, A + B + C = A + B +(Y – B)= A +Y 。这就是将A的值最小化的最佳原因。因此, A的值始终可以为1 。那么B = X – AC = Y – B。
下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to find A, B and C
void MinimumValue(int x, int y)
{
 
    // Keep minimum number in x
    if (x > y)
        swap(x, y);
 
    // Find the numbers
    int a = 1;
    int b = x - 1;
    int c = y - b;
 
    cout << a << " " << b << " " << c;
}
 
// Driver code
int main()
{
    int x = 123, y = 13;
 
    // Function call
    MinimumValue(x, y);
 
    return 0;
}


Java
// Java implementation of the approach
import java.io.*;
 
class GFG
{
 
// Function to find A, B and C
static void MinimumValue(int x, int y)
{
 
    // Keep minimum number in x
    if (x > y)
    {
        int temp = x;
            x = y;
            y = temp;
    }
 
    // Find the numbers
    int a = 1;
    int b = x - 1;
    int c = y - b;
 
    System.out.print( a + " " + b + " " + c);
}
 
// Driver code
public static void main (String[] args)
{
    int x = 123, y = 13;
 
    // Function call
    MinimumValue(x, y);
}
}
 
// This code is contributed by anuj_67..


Python3
# Python3 implementation of the approach
 
# Function to find A, B and C
def MinimumValue(x, y):
 
    # Keep minimum number in x
    if (x > y):
        x, y = y, x
 
    # Find the numbers
    a = 1
    b = x - 1
    c = y - b
 
    print(a, b, c)
 
# Driver code
x = 123
y = 13
 
# Function call
MinimumValue(x, y)
 
# This code is contributed by Mohit Kumar


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
// Function to find A, B and C
static void MinimumValue(int x, int y)
{
 
    // Keep minimum number in x
    if (x > y)
    {
        int temp = x;
            x = y;
            y = temp;
    }
 
    // Find the numbers
    int a = 1;
    int b = x - 1;
    int c = y - b;
 
    Console.WriteLine( a + " " + b + " " + c);
}
 
// Driver code
public static void Main ()
{
    int x = 123, y = 13;
 
    // Function call
    MinimumValue(x, y);
}
}
 
// This code is contributed by anuj_67..


Javascript


输出:
1 12 111