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. 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"< |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 + 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 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