[Solved] Convert any file to binary string and from binary to file [closed]

[ad_1] Finally, I discovered that the problem was in the code. Just small mistake using substr func. So, the correct code is: $buffer = file_get_contents(“image.png”); $length = filesize(“image.png”); if (!$buffer || !$length) { die(“Reading error\n”); } $_buffer=””; for ($i = 0; $i < $length; $i++) { $_buffer .= sprintf(“%08b”, ord($buffer[$i])); } echo $_buffer.”<br>”; $nb = … Read more

[Solved] D-lang being faster than C++? [closed]

[ad_1] find() seems to be heavily used and they are very different in D and C++ implementations: int find(int x) { return ds[x] = (x == ds[x] ? x: find(ds[x])); } vs: long long find(long long node) { if(parents[node] == node)return node; else return find(parents[node]); } find() in D modifies array (looks like some kind … Read more

[Solved] Finding the n-th prime number that is palindrome in base K

[ad_1] Solution: change palindrome to int palindrome ( int n,int base) { int isTrue = 1; int digitCount = digitCountBase(n,base); int power = intPow(base,digitCount-1); int original = n; while (n>0&& digitCount >0) { if (n%base != (original/power) % base &&digitCount!=1) { isTrue =0; return 0; } n=n/base; power = power /base; digitCount=digitCount-2; } return isTrue; … Read more

[Solved] Counting the number of unival subtrees in a binary tree [closed]

[ad_1] int countUniVals(node* head, bool* unival) { if (!node) { *unival = true; return 0; } bool uniL,uniR; int sum = countUniVals(head->l, &uniL) + countUniVals(head->r, &uniR); if (uniL && uniR && (!head->l || head->l->val == head->val) && (!head->r || head->r->val == head->val)) { sum++; *unival = true; } return sum; } 0 [ad_2] solved Counting … Read more

[Solved] Moving chars in String while ignore Numbers

[ad_1] You can try swaping first and last char value like below. =========================================== String s = “asd321tre2”; char[] charr = s.toCharArray(); int end = 0; for (int i = s.length(); i <= 0; i–) { if (Character.isLetter(charr[i])) { end = i; } } String output = charReplace(end, charr); } private static String charReplace(int end, char[] … Read more