Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views3 pages

Sac

The document contains several C++ functions that perform various operations on arrays, including finding the maximum consecutive digits, counting specific values, checking alternating parity, summing digits, and sorting based on digit sums. Each function is defined with specific input parameters and returns results based on the logic implemented. The overall purpose is to manipulate and analyze integer arrays in different ways.

Uploaded by

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

Sac

The document contains several C++ functions that perform various operations on arrays, including finding the maximum consecutive digits, counting specific values, checking alternating parity, summing digits, and sorting based on digit sums. Each function is defined with specific input parameters and returns results based on the logic implemented. The overall purpose is to manipulate and analyze integer arrays in different ways.

Uploaded by

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

1.

void secvmax(int n, int v[], int &c, int &nr)


{
int cmax,nrmax=-1;
c=v[n-1]%10,nr=0;
for(int i=n-1;i>=0;i--)
{
while(v[i]>=10)
{
if(v[i]%10==c)
{
nr++;
if(nr>nrmax)
{
nrmax=nr;
cmax=c;
}
}
else
{
c=v[i]%10;
nr=1;
}
v[i]/=10;
}
if(v[i]==c)
{
nr++;
if(nr>nrmax)
{
nrmax=nr;
cmax=c;
}
}
else
{
c=v[i];
nr=1;
}
}
c=cmax;
nr=nrmax;
}

2.
int count(int n, int v[])
{
int maxi=-1,mini=1000000,c=0;
for(int i=0;i<n;i++)
{
if(v[i]>maxi)
{
maxi=v[i];
}
if(v[i]<mini)
{
mini=v[i];
}
}
for(int i=0;i<n;i++)
{
if(maxi-mini==v[i])
c++;
}
return c;
}

3.
bool yooo(int n, int v[])
{
for(int i=1;i<n-1;i++)
{
if(v[i-1]%2!=v[i+1]%2)
{
return 0;
}
else
{
if(v[i]%2==v[i-1]%2)
return 0;
}
}
return 1;
}

4.
bool secvmax(int n, int v[])
{
for(int i=1;i<n-1;i++)
{
if(v[i-1]%2!=v[i+1]%2)
{
return 0;
}
else
{
if(v[i]%2==v[i-1]%2)
return 0;
}
}
return 1;
}

5.
int sumaCifre(int n)
{
int s=0;
while(n)
{
s+=n%10;
n/=10;
}
return s;
}

void ordonat(int n, int v[])


{
int a[1001],b[1001],k=0,l=0;
for(int i=0;i<n;i++)
{
int y=v[i];
int s=sumaCifre(y);
if(s%2==0)
{
a[k]=v[i];
k++;
}
else
{
b[l]=v[i];
l++;
}
}
sort(a,a+k+1);
sort(b,b+l+1);
int m=0;
for(int i=0;i>=l;i++)
{
if(k>=0)
{v[i]=a[k];
k--;
m++;
}
v[i+1]=b[i];
m++;
}
while(k>=0)
{
v[m]=a[k];
m++,k--;
}
}

You might also like