Search
 
SCRIPT & CODE EXAMPLE
 

CPP

racing horses codechef solution c++

#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;

class solution
{
public:
	void solve()
	{
		int n;
		cin >> n;
		int* arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i];
		}
		sort(arr,arr + n);
		int dif = 0, minimum = INT_MAX;
		for (int i = 0; i < n; i++)
		{
			dif = abs(arr[i] - arr[i + 1]);
			if (dif < minimum)
				minimum = dif;
		}
		cout << minimum << "
";
		delete[] arr;
	}
};
int main()
{
	solution ss;

	int t;
	cin >> t;
	while (t--)
    {
		ss.solve();
	}

	return 0;
}
Comment

racing horses codechef solution c++

#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;

class solution
{
public:
	void solve()
	{
		int n;
		cin >> n;
		int* arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i];
		}
		sort(arr,arr + n);
		int dif = 0, minimum = INT_MAX;
		for (int i = 0; i < n; i++)
		{
			dif = abs(arr[i] - arr[i + 1]);
			if (dif < minimum)
				minimum = dif;
		}
		cout << minimum << "
";
		delete[] arr;
	}
};
int main()
{
	solution ss;

	int t;
	cin >> t;
	while (t--)
    {
		ss.solve();
	}

	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: sprintf add two xeroes for a float number 
Cpp :: subsets of a given array 
Cpp :: ue4 log 
Cpp :: 1672. Richest Customer Wealth leetcode solution in c++ 
Cpp :: hola mundo c++ 
Cpp :: add nested vector cpp 
Cpp :: 2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++ 
Cpp :: constant qualifier c++ "error display" 
Cpp :: lambda - print-out array and add comment 
Cpp :: is there anything like vector<intx[100] 
Cpp :: rand function c++ 
Cpp :: bounded and unbounded solution in lpp 
Cpp :: c++ rainbow text 
Cpp :: Overloading IO Stream 
Cpp :: bullet physics directx 11 
Cpp :: if c++ 
Cpp :: search in vector of pairs c++ 
Cpp :: stack in c++ 
Cpp :: vector to char array c++ 
Cpp :: Arduino Counting 
Cpp :: char * to string c++ 
Cpp :: why ostream cannot be constant 
C :: fahrenheit to celsius formula 
C :: pygame draw transparent rectangle 
C :: print boolean value in c 
C :: type change in c 
C :: successeur nombre chaine 
C :: 0/1 knapsack problem in c 
C :: c output 
C :: c check if char is an operator 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =