Final Population Codechef Solution

Hello Programmers In this post, you will know how to solve the Final Population Codechef Solution. The Problem Code is POPULATION.

Final Population Codechef Solution
Final Population Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

There were initially XX million people in a town, out of which YY million people left the town and ZZ million people immigrated to this town.

Determine the final population of town in millions.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • The first and only line of each test case consists of three integers XX, YY and ZZ.

Output Format

For each test case, output the final population of the town in millions.

Constraints

  • 1≤T≤100
  • 1≤X,Y,Z≤10
  • Y≤X

Sample 1:

Input
4
3 1 2
2 2 2
4 1 8
10 1 10

Output
4
2
11
19

Explanation:

Test case 11: The initial population of the town was 33 million, out of which 11 million people left and 22 million people entered the town. So, final population = 3 – 1 + 2 = 4=3−1+2=4 million.

Test case 22: The initial population of the town was 22 million, out of which 22 million left and 22 million immigrated. The final population is thus 2+2-2 = 22+2−2=2 million.

Final Population Codechef Solutions in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
        public static Scanner sc=new Scanner(System.in);
	public static void main (String[] args) throws java.lang.Exception
	{
		int t,n;
		t=sc.nextInt();
		while(t-- >0){
		    n=sc.nextInt();
		    int arr[]=new int[n];
		    for(int i=0;i<n;i++)
		        arr[i]=sc.nextInt();
		    Arrays.sort(arr);
		    for(int i=0;i<n;i++)
		        System.out.print(arr[i]+" ");
		    System.out.println();
		}
	}
}

Final Population Codechef Solutions in CPP

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n);
	    for(int i=0;i<n;i++)
	    {
	        cout<<a[i]<<" ";
	    }
	    cout<<endl;
	}
	return 0;
}

Final Population Codechef Solutions in Python

for i in range(int(input())):
    n = input()
    lst = list(map(int,input().split()))
    lst.sort()
    for i in lst:
        print(i,end=" ")
    print()
Ezoicreport this ad

Disclaimer: The above Problem (Final Population ) is generated by CodeChef but the solution is provided by  BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Sale Season Codechef Solution

Hello World in C HackerRank Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad