You are on page 1of 2

Problema 1:

void numar(int n, int c, int &m)


{
int p=1, ok=1;
m=0;
while (n)
{
if (n%10!=c)
{
m=n%10*p+m;
ok=0;
p*=10;
}
n/=10;
}
if (ok)
m=-1;
}

Problema 2:

#include <iostream>

using namespace std;

int main()
{
int n, i, j, mat[21][21];
cin>>n;
for (i=1; i<=n; i++)
for (j=1; j<=n-i+1; j++)
mat[i][j]=mat[n-i+1][n-j+1]=n-i-j+1;
for (i=1; i<=n; i++, cout<<'\n')
for (j=1; j<=n; j++)
cout<<mat[i][j]<<' ';
return 0;
}

Problema 3:

#include <iostream>
#include <fstream>

using namespace std;

ifstream fin ("bac.in");

int main()
{
int x, neg1=0, neg2=0, neg3=0, n=0;
while (fin>>x)
{
n++;
if (x<0)
{
if (neg1==0)
neg1=n;
else if (neg2==0)
neg2=n;
else
neg3=n;
}
}
int maxim=max(neg2-1, n-neg2);
cout<<max(maxim, neg3-neg1-1);
return 0;
}

You might also like