1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
int main()
{
char str [MAX];
int n, pair;
srand(time(NULL));
n = 2* (rand() % 10 + 4);
constructArray(str, n);
printArray(str, n);
cout << largestPair(str);
}
void constructArray(char str[], int n)
{
char digits [] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
int k;
for (int i = 0; i < n; i++)
{
k = rand() % 10;
str [i] = digits[k];
if (str[0] == '0')
{
str[0] = digits[k] + 1; //Ensures 1st digit > 0
}
}
}
void printArray (const char str [], int n)
{
cout << "Given ";
for (int i = 0; i < n; i++)
cout << str [i];
cout << endl;
}
|