Temainfoptceidelaclasa

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

#include <iostream>

#include <algorithm>
using namespace std;
bool prim=true;

int v[1001];

int n,i,j,d;

int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>v[i];
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(v[i]>v[j])
{
swap(v[i],v[j]);
}
}
}
for(i=1;i<=n;i++)
{
prim=true;
if(v[i]==0||v[i]==1)prim=false;
else if(v[i]==2||v[i]==3)prim=true;
else if(v[i]%2==0)prim=false;
else {

for (d = 3; d * d <= v[i]; d += 2) {


if (v[i] % d == 0) {
prim = false;
break;
}
}

if(prim==true)
{
cout<<v[i]<<" ";
}

}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;

int v[1001];

int n,i,j,maxi=-99999999,imax;

int main()
{
cin>>n;

for(i=1;i<=n;i++)
{
cin>>v[i];
if(v[i]>maxi)
{
maxi=v[i];
imax=i;
}
}
for(i=1;i<=imax;i++)
{
for(j=i+1;j<=imax;j++)
{
if(v[i]>v[j])
{
swap(v[i],v[j]);
}
}
}

for(i=imax+1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(v[i]<v[j])
{
swap(v[i],v[j]);
}
}
}
for(i=1;i<=n;i++)
{
cout<<v[i]<<" ";
}

return 0;
}

#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

ifstream fin("alfa.in");

ofstream fout("alfa.out");

int n, x,i,in,fi;

int a[1001];
int main()
{

fin >> n >> x;


for(i = 1; i <= n; ++i)
{
fin >> a[i];
}

in = 1, fi = 1;
for(int i = 1; i <= n; ++i)
{
if(a[i] == x)
{
sort(a + in, a + fi);
in = fi + 1;
}
fi++;
}
for(int i = 1; i <= n; ++i)
fout << a[i] <<" ";
}
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sort2.in");
ofstream fout("sort2.out");

int i,j,n,k;

int v[101];

int main()
{
k=1;
while(fin>>v[k])
{
k++;
}

k--;

for(i=1;i<k;i++)
{
for(j=i+1;j<=k;j++)
{
if(v[i]>v[j])
{
swap(v[i],v[j]);
}
}
}

int nr=0;
for(i=1;i<k;i++)
{
if(v[i]>=100)
{
break;
}
fout<<v[i]<<" ";
nr++;

if(nr==0)
{
fout<<"NU EXISTA";
}

return 0;
}
#include <bits/stdc++.h>

using namespace std;

ifstream fin("sortare_divizori.in");
ofstream fout("sortare_divizori.out");

int v[1000],a[1000],n,i,j,x,exponent,ndiv,d;

int main()
{
fin>>n;

for(i=1;i<=n;i++)
{
fin>>v[i];

x=v[i];
exponent=0;
d=2;

while(x%d==0)
{
exponent++;
x/=d;
}

ndiv=exponent+1;
d=3;

while(d*d<=x)
{
exponent=0;

while(x%d==0)
{
exponent++;
x/=d;
}

ndiv*=(exponent+1);
d+=2;
}

if(x!=1)
{
ndiv*=2;
}

a[i]=ndiv;
}

for(i=1;i<n;i++)
{
for(j=i+1; j<=n; j++)
{

if(a[i]<a[j])
{
swap(v[i],v[j]);
swap(a[i], a[j]);
}
else
{
if(a[i]==a[j])
{
if(v[i]>v[j])
{
swap(v[i],v[j]);
}
}
}
}

for(i=1;i<=n;i++)
{
fout<<v[i]<<" ";
}

return 0;
}
#include <bits/stdc++.h>

using namespace std;

int n,v[1001],v1[1001],i,j,k,r;

int main()
{
cin>>n>>k;
for(i=1;i<=n;i++)
{
cin>>v[i];
}

for(i=1;i<=k;i++)
{
r=0;
for(j=i;j<=n;j+=k)
{
v1[r]=v[j];
r++;
}
sort(v1,v1+r);
r=0;
for(j=i;j<=n;j+=k)
{
v[j]=v1[r];
r++;
}
}
for(i=1;i<=n;i++)
{
cout << v[i]<<" ";
}

return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;

int v[1001];
int a[1001];

int n,i,j,d,var,v2,c;
int main()
{
cin>>n;

for(i=1;i<=n;i++)
{
cin>>v[i];
}

for(i=1;i<=n;i++)
{

for(d=1;d*d<=v[i];d++)
{
if(d*d==v[i])
{
var++;
a[var]=v[i];
}
}
}

for(i=1;i<=var;i++)
{
for(j=i+1;j<=var;j++)
{
if(a[i]>a[j])
{
swap(a[i],a[j]);
}
}
}

for(i=1;i<=n;i++)
{
c=0;
for(d=1;d*d<=v[i];d++)
{
if(d*d==v[i])
{
v2++;
cout<<a[v2]<<" ";
c=1;
break;
}
}
if(c==0)
{
cout<<v[i]<<" ";

}
}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;

int v[1001];
int c[1001];

long long n,i,j,cmin=10,cop,cif,cont;


int main()
{
cin>>n;

for(i=1;i<=n;i++)
{
cin>>v[i];
}
for(i=1;i<=n;i++)
{
cop=v[i];
while(cop!=0)
{
cif=cop%10;
cop=cop/10;
if(cif<cmin)
{
cmin=cif;
}
}

c[i]=cmin;
cmin=10;
}

for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(c[i]>c[j])
{
swap(c[i],c[j]);
}
}

cont=1;
while(c[cont]==0)
{
cont++;
}

swap(c[cont],c[1]);

for(i=1;i<=n;i++)
{
cout<<c[i];
}

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy