Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Problema 1:

#include <iostream>
#include <cmath>
using namespace std;
//ifstream cin("sortsum.in");
//ofstream cout("sortsum.out");
int sumcif(int n)
{
int s = 0;
while(n > 0)
{
s += n%10;
n /= 10;
}
return s;
}
int n,v[1005],r[1005];
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> v[i];
}
for(int i = 1; i <= n; i++)
{
if(v[i] < 0)
{
for(int j = i + 1; j <= n; j++)
{
if(v[j] < 0)
{
if(v[i] < v[j])
{
swap(v[i],v[j]);
}
}
}
}
}
for(int i = 1; i <= n; i++)
{
cout << v[i] << " ";
}
return 0;
}
problema 2:
#include <iostream>
#include <cmath>
using namespace std;
//ifstream cin("sortsum.in");
//ofstream cout("sortsum.out");
int sumcif(int n)
{
int s = 0;
while(n > 0)
{
s += n%10;
n /= 10;
}
return s;
}
int n,v[1005],r[1005],w[1005];
int main()
{
cin >> n;
int st = 1;
int dr = n;
for(int i = 1; i <= n; i++)
{
cin >> v[i];
}
while(st < dr)
{
if(v[st]%2 != 0)
{
st++;
}
else if(v[dr]%2 == 0)
{
dr--;
}
else
{
swap(v[st],v[dr]);
st++;
dr--;
}
}
for(int i = 1; i < n; i++)
{
for(int j = i + 1; j <= n; j++)
{
if(v[i] > v[j])
{
swap(v[i],v[j]);
}
}
}
for(int i = 1; i <= n; i++)
{
cout << v[i] << " ";
}
return 0;
}
problema 3:
#include <iostream>
#include <cmath>
using namespace std;
//ifstream cin("sortsum.in");
//ofstream cout("sortsum.out");
int nrcif(int n)
{
int s = 0;
while(n > 0)
{
s++;
n /= 10;
}
return s;
}
int n,v[1005],r[1005],w[1005];
int main()
{
cin >> n;
int st = 1;
int dr = n;
for(int i = 1; i <= n; i++)
{
cin >> v[i];
r[i] = nrcif(v[i]);
}
for(int i = 1; i < n; i++)
{
for(int j = i + 1; j <= n; j++)
{
if(r[i] > r[j])
{
swap(r[i],r[j]);
swap(v[i],v[j]);
}
else if(r[i] == r[j])
{
if(v[i] < v[j])
{
swap(v[i],v[j]);
}
}
}
}
for(int i = 1; i <= n; i++)
{
cout << v[i] << " ";
}
return 0;
}
/*
5
12 13 13 27 11
*/

You might also like