Let blue, red and yellow denote the numbers of blue, red, and yellow balloons, respectively. According to the problem statement, the following equalities hold:
yellow + blue = a (yellow and blue balloons);
red + blue = b (red and blue balloons);
blue + red + yellow = n (the total number of balloons)
From the system of equations, we find the number of balloons of each color:
red = n - a;
yellow = n - b;
blue = a + b - n
Algorithm implementation
Read the input data.
scanf("%d %d %d", &n, &a, &b);Compute and print the answer.
blue = a + b - n;
red = n - a;
yellow = n - b;
printf("%d %d %d\n", blue, red, yellow);Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int n = con.nextInt();
int a = con.nextInt();
int b = con.nextInt();
int blue = a + b - n;
int red = n - a;
int yellow = n - b;
System.out.println(blue + " " + red + " " + yellow);
con.close();
}
} Python implementation
Read the input data.
n, a, b = map(int,input().split())Compute and print the answer.
blue = a + b - n;
red = n - a;
yellow = n - b;
print(blue, red, yellow);