Info
Info
Info
#include <iostream>
using namespace std;
int main ()
{ int n, a[100], i, p, aux=0;
cout<<"n=" ;
cin>>n;
for (i=0; i<n; i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
for (i=0; i<n; i++)
{
p=i-1;
while (p>0 && a[p]<a[p-1])
{
aux=a[p];
a[p]=a[p-1];
a[p-1]=aux;
p--;
}
}
for (i=0; i<n; i++)
cout<<a[i];
}
#include<iostream>
using namespace std;
int main ()
{int n,i,a[100],sf=1,aux=0,j;
cout<<"n="; cin>>n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];}
while (sf!=0)
{sf =0;
for(i=0;i<n;i++)
if(a[i]%2==0)
for(j=i+1;j<n;j++)
if(a[j]%2==0)
if(a[i]>a[j])
{aux=a[i];
a[i]=a[j];
a[j]=aux;
sf=1;}}
for(i=0;i<n;i++)
cout<<"a["<<i<<"]="<<a[i];}
#include<iostream>
using namespace std;
int main ()
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];}
while (sf!=0)
{sf =0;
for(i=0;i<n;i++)
if(a[i]>a[i+1]) DESCRESCATOARE if(a[i]<a[i+1])
{aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
sf=1;}}
for(i=0;i<n;i++)
cout<<"a["<<i<<"]="<<a[i];}
Exercita fisa
1.
#include<iostream>
using namespace std;
int main ()
{int n, k, i, a[100], aux1, aux2, aux, j;
cin<<n<<k;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];}
for(i=0;i<n;i++)
{aux1=a[i];
while ( aux1%k==0)
aux1=aux1/k;
if(aux1==1)
for (j=i+1; j<n; j++)
{aux2=a[j];
while ( aux2%k==0)
aux2=aux2/k;
if(aux==1)
{aux=a[i];
a[i]=a[j];
a[j]=aux;}}}
for(i=0;i<n;i++)
cout<<"a["<<i<<"]="<<a[i];}
2.
#include<iostream>
using namespace std;
int main ()
{int n, sf, i, a[100], j, h, b[100], k, aux;
cin<<n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i]; b[i]=0;}
for(i=0;i<n;i++)
for(j=0; j<n; n++)
for(k=0; k<n; k++)
if(a[i]=a[j]+a[k])
b[i]=1;
if(b[i]==1)
sf=0;
for(i=0;i<n;i++)
if(b[i]==1)
for(j=0; j<n; n++)
if(b[j]==1)
if(a[i]>a[j])
aux=a[j];
a[i]=a[j+1];
aux=a[j+1];
}
for(i=0;i<n;i++)
cout<<a[i];
}
3. ?
#include <bits/stdc++.h>
ifstream fin("divizori4.in");
ofstream fout("divizori4.out");
int P[200000],np;
bool E[1000001];
int nrdiv(int n)
{
int d=1,c=1;
while(n>1)
{
if(n%P[d]==0)
{
int p = 0;
while(n%P[d]==0) n=n/P[d], ++p;
c*=(p+1);
}
else ++d;
if(n>1 && P[d]*P[d]>n)
{
return 2*c;
}
}
return c;
}
int v[50001];
int main()
{
ios::sync_with_stdio(false);
ciur(E,1000001);
prime(1000001,P,np);
int n, c, p;
fin>>n>>c;
for(int i=1;i<=n;++i)
fin>>v[i];
fin>>p;
if(c==1) {fout<<nrdiv(v[p]); return 0;}
else{
int nd = nrdiv(v[p]);
sort(v+1, v+n+1);
for(int i=n;i>0;--i)
if(nrdiv(v[i]) == nd) fout<<v[i]<<' ';
}
return 0;
}
4.?
#include <bits/stdc++.h>
using namespace std;
ifstream fin("crb.in");
ofstream fout("crb.out");
int main()
{
int n;
fin >> n;
int a[1000];
int b[1000];
int cnt=0;
for(int i = 0 ; i < n ; ++i)
{
fin >> a[i];
b[i]=a[i];
}
sort(b , b+n);
for(int i = 0 ; i < n ; ++i)
{
if(a[i]==b[n-i-1])
cnt++;
}
fout << cnt;
return 0;
}
5.
#include<iostream>
using namespace std;
int main ()
{int n, sf, i, a[100], j, aux;
cin<<n;
for(i=0;i<n;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i];
}
for(i=0;i<n;i++)
if(a[i]!=a[i+1])
for(j=0;j<n;j++)
if(a[j]==a[i])
{aux=a[j];
a[j]=a[i+1];
a[i+1]=aux;]
for(i=0;i<n;i++)
if(a[i]!=a[i+1])
sf++;
for(i=0;i<n;i++)
cout<<a[i];<<" " ;
}
6.
#include <bits/stdc++.h>
using namespace std;
ifstream fin("memory007.in");
ofstream fout("memory007.out");
bitset<700020> v ;
long n , m , a , b , i , j , nr , x ;
long long suma , r , t ;
int main()
{
fin >> n >> m >> a >> b ;
for ( i=1 ; i<=n ; i++ )
{
fin >> x ;
j = x-a ;
v[j] = 1 ;
}
j=0;
nr = 0 ;
suma = 0 ;
for ( i=1 ; i<=m ; i++)
{
fin >> x ;
while ( nr < x )
{
nr = nr + v[j] ;
j++ ;
}
suma = suma + j - 1 ;
}
r=m;
t=a;
suma = suma + r * t ;
fout << suma ;
return 0;
}
7.
#include<iostream>
using namespace std;
int main ()
{int m, a, b, sf, i, a[100], m[100], aux;
cin<<m;
cin<<a;
cin<<b;
for(i=0;i<m;i++)
{cout<<"m["<<i<<"]=";
cin>>m[i]; }
for(i=a;i<b+1;i++)
{cout<<"a["<<i<<"]=";
cin>>a[i]; }
for(i=a;i<b+1;i++)
{
sf=1;
while(sf!=0)
{
sf=0;
for(i=a; i<b+1; i++)
{if(a[i]>a[i+1])
aux=a[i];
a[i]=a[i+1];
a[i+1]=aux;
sf=1;
}
}
}
cout<<"codul seifului este"
for(i=a;i<b+1;i++)
cout<<a[m];<<" "
}
8.
#include <bits/stdc++.h>
using namespace std;
ifstream cin("intervale.in");
ofstream cout("intervale.out");
struct an
{
int i , j;
}a[105];
int n , rez[105] , cnt;
int main()
{
cin >> n;
for(int i = 1 ; i <= n ; ++i)
cin >> a[i].i >> a[i].j;
for(int i = 1 ; i <= n ; ++i)
{
int ok = 0;
for(int j = 1 ; j <= n ; ++j)
if(i != j &&(a[i].i < a[j].j && a[i].j > a[j].i)) ok = 1;
if(ok == 0) rez[++cnt] = i;
}
cout << cnt << "\n";
for(int i = 1 ; i <= cnt ; ++i)
cout << a[rez[i]].i << " " << a[rez[i]].j << "\n";
return 0;
}
9.
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;
ifstream fin("sort.in");
ofstream fout("sort.out");
int a,v[50002],w[50002],i,j,k,ok,minim,maxim,n,m,x,o,p,y,s;
int main(){
fin>>n;
for(i=1;i<=n;i++){
fin>>v;
w=v;
}
sort(w+1,w+n+1);
maxim=1;
for(i=1;i<=n;i++){
if(w>maxim){
x=i-1;
break;
}
}
maxim=3;
for(i=n;i>=1;i--){
if(w<maxim){
y=i;
break;
}
}
for(i=1;i<=y;i++){
if(i<=x&&v!=1){
for(j=n;j>x;j--){
if(v[j]==1){
s++;
m=v;
v=v[j];
v[j]=m;
break;
}
}
}
if(i>x&&i<=y&&v!=2){
for(j=n;j>y;j--){
if(v[j]==2){
s++;
m=v;
v=v[j];
v[j]=m;
break;
}
}
}
}
fout<<s;
return 0;
}