0% found this document useful (0 votes)
62 views2 pages

Notes For Ecpc (Print It Before Contest)

The document contains code snippets for finding the maximum sum of an array, comparing pairs based on their second element, converting an integer to binary representation, and converting a binary number to decimal.

Uploaded by

braagamer82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Notes For Ecpc (Print It Before Contest)

The document contains code snippets for finding the maximum sum of an array, comparing pairs based on their second element, converting an integer to binary representation, and converting a binary number to decimal.

Uploaded by

braagamer82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

-1int maxSubArraySum(int a[], int size)

{
int max_so_far = INT_MIN, max_ending_here = 0;

for (int i = 0; i < size; i++) {


max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;

if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
‫عشان ال‬maximum sum of array

-2 bool cmp(const pair<int,int> &a,

const pair<int,int> &b)


{
return (a.second < b.second);
}

3-void decToBinary(int n)

{
// array to store binary number
int binaryNum[32];

// counter for binary array


int i = 0;
while (n > 0) {

// storing remainder in binary array


binaryNum[i] = n % 2;
n = n / 2;
i++;
}

// printing binary array in reverse order


for (int j = i - 1; j >= 0; j--)
cout << binaryNum[j];
}
4-int bintodec(long long n) {
int dec = 0, i = 0, rem;

while (n!=0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}

return dec;
}

You might also like