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

Problema 1

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("numere.in");
ofstream fout("numere.out");
bool cifpar(int a)
{

while(a)
{
if(a%2==1)
return false;
a/=10;
}
return true;
}
int main()
{
int n,x;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x;
if(cifpar(x))
fout<<x<<' ';
}
return 0;
}

Problema 2

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

int main()
{
int n;
fin>>n;
int x=n;
while(x)
{
x/=10;
fout<<x%10<<' ';
x/=10;
}
return 0;
}

Problema 3
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

int main()
{
int n, v,minim=1000000000 , pos;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>v;
if(v%2!=0)
if(v<minim)
{
minim=v;
pos=i;
}
}
fout<<minim<<' '<<pos;
return 0;
}

Problema 4
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

int main()
{
int n[51],k=1,d;
while(fin>>n[k] && k<=50)
{

fout<<n[k]<<' ';
d=2;
while(d<=n[k]/2 )
{
if(n[k]%d==0)
fout<<d<<' ';
d++;
}
fout<<endl;
k++;
}
return 0;
}

Problema 5
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("Numere.txt");
int prim( int a)
{
int d=3;
if(a==1 )
return 0;
if(a==2)
return 1;
while(d<a/2 && a%d !=0)
d++;
if(a%d==0)
return 0;
else return 1;

}
int main()
{
int n,p=1;
while(fin>>n )
{
if(p==1)
if(prim(n))
{
cout <<n ;
p=0;
}
}
if(p==1)
cout<<"NU EXISTA";
return 0;
}

Problema 6
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("numere.in");
ofstream fout("numere.out");
int pal(int a)
{
int aux=a,pal=0;
while(aux)
{
pal=pal*10+aux%10;
aux/=10;
}
if(pal==a)
return 1;
else return 0;
}
int main()
{
int n,maxim=0;
while( fin>>n)
{
if(maxim<n)
if(pal(n))
maxim=n;
}
fout<<maxim;
return 0;
}

Problema 7
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

int nr_cif(int a)
{
int nr=0;
while(a)
{
a/=10;
nr++;
}
return nr;
}
int main()
{
int n,v;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>v;
if(v%2==1)
fout<<nr_cif(v)<<' ';
}
return 0;

Problema 8

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("tip1.in");
ofstream fout("tip1.out");

int main()
{
int n , k;
fin>>n>>k;
int aux=0,x=n,p=1;
while(x)
{
if(x%10!=k)
{
aux=(x%10)*p+aux;
p=p*10;
}
x/=10;
}
fout<<aux;
return 0;
}

Problema 9

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("puncte.txt");

int main()
{
int x,y;
int nr=0;
while(fin>>x>>y)
{
if(x>=0 & y>=0)
nr++;
}
cout<<nr;
return 0;
}

Problema 10

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fractii.txt");

int cmmdc(int x, int y)


{
int rest;
while(y!=0)
{
rest=x%y;
x=y;
y=rest;
}
return x;
}
int main()
{
struct fractie{
int x;
int y;
}f;
int n,nr=0;;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>f.x>>f.y;
if(cmmdc(f.x,f.y)==1)
nr++;
}
cout<<nr;
return 0;
}

Problema 11

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

void schimb(int &a,int &b)


{
int aux=a;
a=b;
b=aux;
}
int main()
{
struct XYZ{
int x;
int y;
int z;
}pos[11];
int n;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>pos[i].x>>pos[i].y>>pos[i].z;
}
for(int i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
{
if(pos[i].z>pos[j].z)
{
schimb(pos[i].x,pos[j].x);
schimb(pos[i].y,pos[j].y);
schimb(pos[i].z,pos[j].z);
}
}
for(int i=1;i<=n;i++)
{
fout<<'('<<pos[i].x<<','<<pos[i].y<<','<<pos[i].z<<')';
fout<<endl;
}
return 0;
}

Problema 12

#include <iostream>
#include <fstream>

using namespace std;

int oglindit( int x)


{
int ogl=0, c;
while(x!=0)
{
c=x%10;
ogl=ogl*10+c;
x=x/10;

}
return ogl;
}

int main()
{
ifstream f("numere.in");
ofstream g("numere.out");
int n,i,x;
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
if(oglindit(x)==x)
g<<x<<" ";

return 0;
}

Problema 13
#include <iostream>
#include <fstream>
using namespace std;
int sum_cif(int n)
{
int s=0;
while (n!=0)
{
s=s+n%10;
n=n/10;
}
return s;
}

int main()
{
int n, i, x;
ifstream f("numere.in");
ofstream g("numere.out");
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
g<<sum_cif(x)<<" ";
}
return 0;
}

Problema 14
#include <iostream>
#include <fstream>
using namespace std;

int main()
{ int n, i, x, s=0, nr=0;
ifstream f ("atestat.in");
ofstream g ("atestat.out");
f>>n;
for (i=1;i<=n;i++)
{
f>>x;
if (i%2==1)
{
s=s+x;
nr++;

}
}
g<<(float)s/nr;
return 0;
}

Problema 15
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc(int a, int b)
{
while(a!=b)
if (a>b)
a=a-b;
else b=b-a;
return a;
}
int main()
{
int n, i, x[1001], j, OK=1;
ifstream f("numere.in");
ofstream g("numere.out");
f>>n;
for(i=1;i<=n;i++)
f>>x[i];
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(cmmdc(x[i], x[j])!=1)
OK=0;
if(OK)
g<<"DA";
else g<<"NU";
return 0;
}

Problema 16
#include <iostream>
#include<fstream>
using namespace std;
int prefix(int n)
{int ok=0;
while(n!=0&&ok==0)
{
if(n%10==0)
ok=1;
n=n/10;
}
return ok;
}
int main()
{
ifstream f("numere.in");
ofstream g("numere.out");
int x,nr=0;
while (f>>x)
{
if(prefix(x))
nr++;
}

g<<nr;
return 0;
}

Problema 17
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

int primm(int a)
{
int aux =a;
int x=0,p=1;;
while(aux>9)
{
x=x+aux%10*p;
aux/=10;
p*=10;
}
return x;
}
int main()
{
int n;
while(fin>>n)
{
fout<<primm(n)<<' ';
}
return 0;
}

Problema 18
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

int main()
{
int n,v[31];
fin>>n;
for(int i=1;i<=n;i++)
fin>>v[i];
int aux;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(v[i]<v[j])
{
aux=v[i];
v[i]=v[j];
v[j]=aux;
}
for(int i=1;i<=n;i++)
if(v[i]%2==0)
fout<<v[i]<<' ';
return 0 ;
}

Problema 19
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("numere.in");
ofstream fout("numere.out");

int main()
{
int n,v;
fin>>n;
int minim=0;
while(n)
{
fin>>v;
if(minim<=v)
minim=v;
else {
fout<<"NU";
return 0;
}
n--;
}
fout<<"DA";
return 0 ;
}

Problema 20
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");
int cif_z( int a)
{
a/=10;
if(a%2==1)
return 1;
else return 0;
}
int main()
{
int n ,x;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x;
if(cif_z(x))
fout<<x<<' ';
}
return 0;
}

Problema 21
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("tip2.in");
ofstream fout("tip2.out");
int sum_c( int a)
{
int s=0;
while(a)
{
s+=a%10;
a/=10;
}
return s;
}
int main()
{
int n , x;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x;
if(sum_c(x)%2==0)
fout<<x<<' ';
}
return 0;
}

Problema 22
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("tablou.in");
ofstream fout("tablou.out");
void schimb(int &a , int &b)
{
int aux;
if(a>b)
{
aux=a;
a=b;
b=aux;
}
}
int main()
{
int n , x[101];
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x[i];
}
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
schimb(x[i],x[j]);
for(int i=1;i<=n;i++)
fout<<x[i]<<' ' ;
return 0;
}

Problema 23
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");
int prim(int a)
{
int d=2;
if(a==2)
return 1;
if(a==0 || a==1)
return 0;
while(d*d<a && a%d!=0)
d++;
if(a%d==0)
return 0;
else return 1;
}
int main()
{

int n , a[101][101];
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
fin>>a[i][j];
}
int ok=1;
int nr=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i+j>n+1)
if(prim(a[i][j]))
{
ok=0;
nr++;
}

if(ok)
fout<<"nu exista";
else fout<<nr;
return 0;
}

Problema 24
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("matrice.txt");
ofstream fout("matrice.out");

int main()
{
struct mat{
int v;
int l;
int c;
}m;

int n,p;
fin>>n>>p;
int a[n][n];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=0;
for(int i=1;i<=p;i++)
{
fin>>m.v>>m.l>>m.c;
a[m.l][m.c]=m.v;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
fout<<a[i][j]<<' ';
fout<<endl;
}
return 0;
}

Problema 25
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");
int prim(int a)
{
int d=2;
if(a==0||a==1)
return 0;
if (a==2)
return 1;
while(d*d<a && a%d!=0)
d++;
if(a%d==0)
return 0;
else return 1;
}
int main()
{
int n,a[21][21];
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
fin>>a[i][j];
for(int j=1;j<=n;j++)
{
int nr=0;
for(int i=1;i<=n;i++)
{
if(prim(a[i][j]))
nr++;
}
fout<<nr<<' ';
}

return 0;
}

Problema 26
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("matrice.in");
ofstream fout("matrice.out");

int main()
{
int n,a[21][21];
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
fin>>a[i][j];
int maxim=-9999999999;
for(int j=1;j<=n;j++)
for(int i=1;i<=n;i++)
if(i+j==n+1)
if(maxim<a[j][i])
maxim=a[j][i];
fout<<maxim;

return 0;
}

Problema 27
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");
int suma_div_p(int a)
{
int s=1,d,n=a;
for(d=2;d*d<=n;d++)
{
if(n%d==0)
{
s+=d;
if(d!=n/d)
s+=n/d;
}
}
if(s==a)
return 1;
else return 0;
}
int main()
{
int n,a[21][21];
fin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
fin>>a[i][j];
int ok=1;
int nr=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(suma_div_p(a[i][j]))
{
ok=0;
nr++;
}
if(ok)
fout<<"Nu exista numere perfecte";
else fout<<nr;
return 0;
}

Problema 28
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

int main()
{
char s[101];
fin.get(s,101);
for(int i=0;i<strlen(s);i++)
{
if(s[i]>='0' && s[i]<='9')
{
if(s[i+1]==' ')
strcpy(s+i,s+i+2);
else strcpy(s+i,s+i+1);
}
}
fout<<s;
return 0;
}

Problema 29
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

int main()
{
char s[201];
fin.get(s,201);
// strupr(s); functie care face toate literele mari
for(int i=0;i<strlen(s);i++) // echivalentul functie de mai sus
if(s[i]>='a'&&s[i]<='z')
s[i]-=32;

fout<<s;
return 0;
}

Problema 30
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("atestat.in");
ofstream fout("atestat.out");

int main()
{
char s[71];
fin.get(s,71);
for(int i=0;i<strlen(s);i++)
{
if(s[i]>='a'&&s[i]<='z')
s[i]-=32;
else if(s[i]>='A'&&s[i]<='Z')
s[i]+=32;
}
fout<<s;
return 0;
}

You might also like