Created
December 21, 2015 11:54
-
-
Save poseidon4o/8b01f1f781a226fd7496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
/// group A | |
int Dist(unsigned A, unsigned B) { | |
int difference = 0; | |
for (int c = 0; c < 32; ++c) { | |
int bitA = (A >> c) & 1; | |
int bitB = (B >> c) & 1; | |
if (bitA != bitB) { | |
++difference; | |
} | |
} | |
return difference; | |
} | |
double Calculate(double * A, int N, double x) { | |
double result = 0; | |
for (int c = 0; c < N; ++c) { | |
result += A[c] * pow(x, c); | |
} | |
return result; | |
} | |
unsigned Replace9(unsigned Value) { | |
unsigned result = 0; | |
int digits = log10(Value); | |
for (int c = 0; c < digits; ++c) { | |
int current = (Value / (int)pow(10, c)) % 10; | |
int next = (Value / (int)pow(10, c + 1)) % 10; | |
if (current == next) { | |
do { | |
result += 9 * pow(10, c); | |
++c; | |
current = (Value / (int)pow(10, c)) % 10; | |
next = (Value / (int)pow(10, c + 1)) % 10; | |
} while (current == next); | |
result += 9 * pow(10, c); | |
} else { | |
result += current * pow(10, c); | |
if (c == digits - 1) { | |
result += next * pow(10, c + 1); | |
} | |
} | |
} | |
return result; | |
} | |
/// group B | |
bool SameDig(unsigned A, unsigned B) { | |
for (int c = 0; c < 10; ++c) { | |
unsigned copyA = A, copyB = B; | |
bool inA = false, inB = false; | |
while (copyA) { | |
inA = copyA % 10 == c || copyA; | |
copyA /= 10; | |
} | |
while (copyB) { | |
inB = copyB % 10 == c || copyB; | |
copyB /= 10; | |
} | |
if (inA != inB) { | |
return false; | |
} | |
} | |
return true; | |
} | |
void Derive(double * A, int N, double * B) { | |
for (int c = 1; c < N; ++c) { | |
B[c - 1] = A[c] * c; | |
} | |
} | |
unsigned MoreOnes(unsigned A, unsigned B) { | |
int setBitsA = 0, setBitsB = 0; | |
for (int c = 0; c < 32; ++c) { | |
setBitsA += (A >> c) & 1; | |
setBitsB += (B >> c) & 1; | |
} | |
return setBitsA > setBitsB ? A : B; | |
} | |
int main() { | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment