From 598729923aec22a29852167bb5e22b229cf97b1f Mon Sep 17 00:00:00 2001 From: Ritesh N Das <148974606+rndastech@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:04:13 +0530 Subject: [PATCH 1/6] Create statement.txt --- Problem-setting/rndastech-1/statement.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Problem-setting/rndastech-1/statement.txt diff --git a/Problem-setting/rndastech-1/statement.txt b/Problem-setting/rndastech-1/statement.txt new file mode 100644 index 0000000..944db15 --- /dev/null +++ b/Problem-setting/rndastech-1/statement.txt @@ -0,0 +1,5 @@ +Title +Hex Sort + +Problem Statement +A hexadecimal number consists of numbers 0-9 and letters A-F, where A = 10, B = 11,..., F = 15. Given a hexadecimal number x, let the minimum and maximum number formed possible by rearranging all the hexadecimal digits without adding or removing any digit and without containing leading zeros (except the number 0) be denoted by minx and maxx respectively. Is |maxx - x| > |x - minx|? From 79aa31e01a6ca1bfb81131ebe88ad149f745645c Mon Sep 17 00:00:00 2001 From: Ritesh N Das <148974606+rndastech@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:04:57 +0530 Subject: [PATCH 2/6] Create solution.cpp --- Problem-setting/rndastech-1/solution.cpp | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Problem-setting/rndastech-1/solution.cpp diff --git a/Problem-setting/rndastech-1/solution.cpp b/Problem-setting/rndastech-1/solution.cpp new file mode 100644 index 0000000..1b101ea --- /dev/null +++ b/Problem-setting/rndastech-1/solution.cpp @@ -0,0 +1,61 @@ +#include +using namespace std; + long long int exp(long long int x, long long int n) { + long long int res = 1; + while (n > 0) { + if (n % 2 == 1) { res = res * x; } + x = x * x; + n /= 2;} + return res;} + bool cmp(char f, char s){ + char arr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + long long int p1, p2; + for(long long int i = 0; i<16;i++){ + if(f==arr[i]) + p1 = i; + if(s==arr[i]) + p2 = i;} + return (p1>=p2);} + long long int hexint(string s, long long int n){ + long long int ans = 0; + for(long long int i=0;i='A' && s[i]<='F'){ + ans+= (s[i]-'A'+10)*exp(16, n-1-i);} + if(s[i]>='0' && s[i]<='9'){ + ans+= (s[i]-'0')*exp(16, n-1-i);}} + return ans; + } + int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + long long int t; + cin>>t; + while(t--){ + string xs; + cin>>xs; + if(xs=="0"){ + cout<<"NO"< x - minx) + cout<<"YES"< Date: Wed, 18 Dec 2024 11:06:18 +0530 Subject: [PATCH 3/6] Update statement.txt --- Problem-setting/rndastech-1/statement.txt | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Problem-setting/rndastech-1/statement.txt b/Problem-setting/rndastech-1/statement.txt index 944db15..e404632 100644 --- a/Problem-setting/rndastech-1/statement.txt +++ b/Problem-setting/rndastech-1/statement.txt @@ -3,3 +3,28 @@ Hex Sort Problem Statement A hexadecimal number consists of numbers 0-9 and letters A-F, where A = 10, B = 11,..., F = 15. Given a hexadecimal number x, let the minimum and maximum number formed possible by rearranging all the hexadecimal digits without adding or removing any digit and without containing leading zeros (except the number 0) be denoted by minx and maxx respectively. Is |maxx - x| > |x - minx|? + + +Input Format + Constraints +The first line contains an integer t (1≤t≤10^5) — the number of test cases. +The only line of each test case contains a string x (1<= x.size <=10) consisting of digits ‘0’ - ‘9’ and letters ‘A’ - ‘F’. + +Output Format +For each test case, print on one line "YES" if |maxx - x| > |x - minx|. Otherwise, print "NO". + + +Explanation: +For 1st test case, +minx = ABCD +maxx = DCBA +maxx - x = 30ED +x - minx = 0 +Therefore, maxx - x > x - minx + +For 2nd test case, +minx = 8 +maxx = 8 +maxx - x = 0 +x - minx = 0 +Therefore, maxx - x = x - minx + From f1ca33a49e980058f77789a69e1fc01a5b6ab6a8 Mon Sep 17 00:00:00 2001 From: Ritesh N Das <148974606+rndastech@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:06:50 +0530 Subject: [PATCH 4/6] Create test0.in --- Problem-setting/rndastech-1/test0.in | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Problem-setting/rndastech-1/test0.in diff --git a/Problem-setting/rndastech-1/test0.in b/Problem-setting/rndastech-1/test0.in new file mode 100644 index 0000000..7c838a0 --- /dev/null +++ b/Problem-setting/rndastech-1/test0.in @@ -0,0 +1,3 @@ +2 +ABCD +8 From 551482f0fb5fa8759bbdc158db11f3ce2e72d85f Mon Sep 17 00:00:00 2001 From: Ritesh N Das <148974606+rndastech@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:07:05 +0530 Subject: [PATCH 5/6] Create test0.out --- Problem-setting/rndastech-1/test0.out | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Problem-setting/rndastech-1/test0.out diff --git a/Problem-setting/rndastech-1/test0.out b/Problem-setting/rndastech-1/test0.out new file mode 100644 index 0000000..823d3f6 --- /dev/null +++ b/Problem-setting/rndastech-1/test0.out @@ -0,0 +1,2 @@ +YES +NO From 5be645883e218618b52e95ebd6b1deed04e2a1a4 Mon Sep 17 00:00:00 2001 From: Ritesh N Das <148974606+rndastech@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:07:39 +0530 Subject: [PATCH 6/6] Create explanation.txt --- Problem-setting/rndastech-1/explanation.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Problem-setting/rndastech-1/explanation.txt diff --git a/Problem-setting/rndastech-1/explanation.txt b/Problem-setting/rndastech-1/explanation.txt new file mode 100644 index 0000000..c77d9ad --- /dev/null +++ b/Problem-setting/rndastech-1/explanation.txt @@ -0,0 +1,4 @@ +For calculating maxx, we can sort the given string x using a comparator function where the priority is given as F>E>D…>A>9>8>7…>1>0. +To find the minx, we can reverse maxx. If minx contains leading zeros, we can use a for loop to find the position of the first non zero number and swap it with the first position of minx. +To compare the hexadecimal numbers, we can convert them to integers and then compare them. +We need to check for “0” manually as it is the only number having leading zeros.