Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Probleme Info Atestat

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

Bilet 1

#include <iostream>

using namespace std;


int cnt;
int fibo(int n,int m)
{
int f1,f2,f3;
int f11,f22,f33;
f11=f22=1;
f33=f11+f22;
f1=f2=1;
f3=f1+f2;
if(n!=m)
{
while(f3<=n)
{
f1=f2;
f2=f3;
f3=f1+f2;
}
return f2;
}
while(f33<m)
{
f11=f22;
f22=f33;
f33=f11+f22;
}
return f22;
}
int main()
{
int n=192,s;
int m=n;
while(n>1)
{
s=fibo(n,m);
n-=s;
if(s==-1)
return 0;
if(n!=0)
cout<<s<<"+";
else
cout<<s;
cnt++;
}
if(n==1)
cout<<1;
return 0;
}

Bilet 2
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("numere.in");
int v[100];///Facem un vector de frecventa pentru numerele de maxim doua
cifre
int main()
{
int x,lgmax=0,p;
while(fin >> x)
{
v[x]++;
if(v[x]>lgmax)///Verificam daca intalnim un numar care se repeta de
mai multe ori decat lungimea maxima initiala
{
lgmax=v[x];
p=x;
}
}
cout << x;
return 0;
}

Bilet 3
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("numere.in");
int v[10];
int main()
{
int i,x,n,k,c,p;
long long s=0;
fin >> n;
for(i=1;i<=n;i++)
{
fin >> x;
///Cifrele numarului sunt memorate intr-un vector
v[i]=x;
}
k=n;
while(k!=0)
{
c=0;
for(i=1;i<=n;i++)
c=c*10+v[i];
s=s+c;
///Urmeaza permutarea vectorului spre dreapta
p=v[n];
for(i=n;i>1;i--)
v[i]=v[i-1];
v[1]=p;
k--;
}
cout << s;
return 0;
}
Bilet 4
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("cuvinte.in");
char c[100][50];
int main()
{
int i,j,n=1;
char aux[50];
while(fin.getline(c[n],50))
n++;
n-=2;
for(i=1; i<n; i++)
for(j=i; j<=n; j++)
if(strcmp(c[i],c[j])>0)
{
strcpy(aux,c[i]);
strcpy(c[i],c[j]);
strcpy(c[j],aux);
}
for(i=1; i<=n; i++)
cout << c[i] << endl;
return 0;
}

Bilet 5
#include <iostream>
using namespace std;
int a[21][21],s,i,j,n,k;

void sub(int &s,int n,int a[21][21],int k)


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

if(i+j==k)
s=a[i][j]+s;
}
int main()
{
cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
int suma;
suma=0;
for(k=2;k<=n;k++)
{sub(s,n,a,k);
suma=suma+s;
}
cout<<suma;
return 0;
}

Bilet 6
#include <bits/stdc++.h>
using namespace std;
bool prim (int x )
{
int i;
if(x<2)
return 0;
for(i=2; i*i<=x; i++)
if(x%i==0)
return 0;
return 1;
}
int main()
{ int a,b,i,exp,ok,nr,minim;
cin>>a>>b;
ok=0;
minim=a+b;
for(i=a; i<=b; i++)
{
if(prim(i)==1)
{
exp=abs(a+b-2*i);
ok=1;
if(exp<minim)
{
nr=i;
minim=exp;
}
}
}
if(ok==1)
cout<<nr;
else cout<<0;
return 0;
}

Bilet 7
#include <bits/stdc++.h>
using namespace std;
void apcar( char s[256], char c, int &p)
{
p=0;
int i;
for(i=0; i<strlen(s); i++)
if(c==s[i])
p++;
}

int main()
{
char voc[]="AEIOU",s[256];
int p,i,nr;

cin>>s;
nr=0;
for(i=0; i<strlen(voc); i++)
{
apcar(s,voc[i],p);
nr=nr+p;
}
cout<<nr;

return 0;
}

Bilet 8
#include <iostream>

using namespace std;


int a,b,nr,i,n;
float v[100];
int main()
{
cin>>n;
nr=0;
for(i=1; i<=n; i++)
cin>>v[i];
if(v[1]>v[n])
{
a=v[n];
b=v[1];
}
else
{
b=v[n];
a=v[1];
}
for(i=2; i<n; i++)
if(v[i]<a||v[i]>b)
nr++;
cout<<nr;
return 0;
}

Bilet 9
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bac.txt");
int n,m,a[5001],b[5001],poz,ok;
int main()
{
fin >> n >> m;
for(int i=1; i<=n; ++i)
fin >> a[i];
for(int j=1; j<=m; ++j)
fin >> b[j];
///cautam fiecare element din b in a
///daca nu il gasim afisam mesaj
///si daca il gasim urmatoare cautare va fi
///de la pozitia la care l-am gasit + 1
poz=1;
for(int j=1; j<=m; ++j) {
ok = 0;
for(int i=poz; i<=n; ++i)
if(b[j] == a[i]) {
ok = 1;
poz = i+1;
break;
}
if(ok == 0)
{
cout << "b nu se poate obtine din a";
return 0;
}
}
cout << "b se poate obtine din a";
return 0;
}

Bilet 10
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bac.txt");
int fr[100], x, lgm, i;
int main()
{
///fr[x] memoreaza prima aparitie a lui x in sir
///cand citim un x si fr[x] nu este 0, inseamna
///ca era deja in vector si calculam distanta
///dintre prima aparitie si aparitia curenta
///si o comparam cu distanta maxima
while(fin >> x) {
i++;
if(fr[x] == 0)
fr[x] = i;
else {
if(i-fr[x] > lgm)
lgm = i-fr[x];
}
}
cout << lgm;
return 0;
}

Bilet 11
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("matrice.in");
ofstream fout("matrice.out");
int suma(int x[11][11], int n, int p)
{
int s=0;
for(int i=1; i<=n; ++i)
s+= x[p][i];
return s;
}
int main()
{
int x[11][11],n;
fin >> n;
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
fin >> x[i][j];
for(int i=1; i<=n; ++i) {
int s;
s=suma(x,n,i);
if(s%2 == 0)
fout << i << ' ';
}
return 0;
}

Bilet 12
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int n, x;
bool prim(int x)
{
if(x < 2 || x!=2 && x%2 == 0)
return 0;
for(int d=3; d*d<=x; d=d+2)
if(x%d == 0)
return 0;
return 1;
}

int main()
{
fin >> n;
for(int i=1; i<=n; ++i) {
fin >> x;
if(prim(x) == 1)
fout << x << ' ';
}
return 0;
}

Bilet 13
#include <iostream>
using namespace std;

int v[22], a[11][11], n;

int main()
{
cin >> n;
for(int i=1; i<=n; ++i)
v[i]=i;
for(int i=n+1; i<=2*n; ++i)
v[i] = i-n;
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=n; ++j)
a[i][j] = v[i+j-1];
}
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=n; ++j)
cout << a[i][j] << ' ';
cout << endl;
}
return 0;
}

Bilet 14
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("date.in");
ofstream fout ("date.out");
int test_fibo (int x)
{
int a1=1,a2=1,a3=0;
while(a3<x)
{
a3=a1+a2;
a1=a2;
a2=a3;
}
if(a3==x||x==1)
return 1;

else
return 0;
}
int n,x,i;
int main()

{
fin>>n;
for(i=1;i<=n;i++)
{
fin>>x;
if (test_fibo(x)==1)
fout<<x<<" ";
}
return 0;
}

Bilet 15
#include <bits/stdc++.h>

using namespace std;


ifstream fin("numere.in");
ofstream fout("numere.out");
int a,b, fr[10],i,c;
int main()
{
fin>>a>>b;
while(a)
{
c=a%10;
fr[c]++;
a=a/10;
}
while(b)
{
c=b%10;
fr[c]++;
b=b/10;
}
for(i=9; i>=0; i--)
while(fr[i])
{
fout<<i;
fr[i]--;
}
return 0;
}

Bilet 16
#include <bits/stdc++.h>

using namespace std;


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

void afisare(int n,int b)


{
if(n==0)
return;
afisare(n/b,b);
fout<<n%b;

}
int main()
{ int b1,b2,b3,x,y,p,noux,nouy,nou;
noux=0;
nouy=0;
fin>>b1>>b2>>b3;
fin>>x>>y;

p=1;
while(x)
{

noux=noux+x%10*p;
p=p*b1;
x=x/10;

}
p=1;
while(y)
{

nouy=nouy+y%10*p;
p=p*b2;
y=y/10;

}
nou=noux+nouy;
afisare(nou,b3);

return 0;
}

Bilet 17
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int n,x;
int suma_cifre(int x)
{
if(x == 0)
return 0;
return x%10 + suma_cifre(x/10);
}

int main()
{
fin >> n;
for(int i=1; i<=n; ++i) {
fin >> x;
if(suma_cifre(x)%3 == 0)
fout << x << ' ';
}
return 0;
}
Bilet 18
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("multimi.in");
ofstream fout("multimi.out");
int n,m, a[101],b[101],c[202], i, j, nr;

int main()
{
fin >> n >> m;
for(int i=1; i<=n; ++i)
fin >> a[i];
for(int j=1; j<=m; ++j)
fin >> b[j];
///algoritmul de interclasare
i=1;
j=1;
while(i <=n && j<=m)
{
if(a[i] < b[j])
{
nr++;
c[nr]=a[i];
i++;
}
else if(a[i] > b[j])
{
nr++;
c[nr]=b[j];
j++;
}
else
{
nr++;
c[nr]=a[i];
i++;
j++;
}
}
while(i<=n)
{
nr++;
c[nr] = a[i];
i++;
}
while(j<=m)
{
nr++;
c[nr]=b[j];
j++;
}
for(int i=1; i<=nr; ++i)
fout << c[i] << ' ';
return 0;
}
Bilet 19
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

int a[101][101],n,vmax,vmin,ok;

int main()
{
fin >> n;
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
fin >> a[i][j];
///VMIN si VMAX sunt valorile minime si maxime din toata matricea
vmin=vmax=a[1][1];
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
{
if(a[i][j] < vmin)
vmin = a[i][j];
if(a[i][j] > vmax)
vmax = a[i][j];
}
for(int i=1; i<=n; ++i)
{
ok = 0;
///verific daca pe linia i exista valoarea maxima
for(int j=1; j<=n; ++j)
if(a[i][j] == vmax)
{
ok=1;
break;
}
if(ok == 1)
{
for(int j=1; j<=n; ++j)
a[i][j] += vmin;
}
}
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=n; ++j)
fout << a[i][j] << ' ';
fout << endl;
}
return 0;
}
Bilet 20
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");

int a,b,fr[10];

int main()
{
fin >> a >> b;
///punem cifrele intr-un vector de frecventa
do{
fr[a%10]++;
a/=10;
}
while(a!=0);
do{
fr[b%10]++;
b/=10;
}
while(b!=0);
///afisam prima cifra nenula
for(int i=1; i<=9; ++i)
if(fr[i]!=0)
{
fout << i;
fr[i]--;
break;
}
///daca au aparut si zerouri le scriem
if(fr[0] != 0)
{
for(int j=1; j<=fr[0]; ++j)
fout << 0;
}
///scriem restul cifrelor in ordine crescatoare
for(int i=1; i<=9; ++i)
if(fr[i]!=0)
{
for(int j=1; j<=fr[i]; ++j)
fout << i;
}
return 0;
}

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

char s[201], *p;


///returneaza true daca este un cnp valid cu 13 caractere
///toate cifre
bool is_CNP(char p[])
{
if(strlen(p) != 13)
return false;
for(int i=0; i<strlen(p)-1; ++i)
if(p[i] < '1' && p[i] >'9')
return false;
return true;
}

int main()
{
while(fin.get(s,201))
{
///functia strtok extrage un cuvant din sir
p = strtok(s, " ,;.");
while(p!=NULL){
if(is_CNP(p))
fout << p << endl;
p=strtok(NULL, " ,;.");
}
fin.get();
}
return 0;
}

Bilet 22
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("numere.in");
int i,nrcif,a,n,x,p=1,perm,nr;
int main()
{
fin >>n;
for(i=1; i<=n; i++)
{
fin>>x;
a=x;
nrcif=0;
p=1;
while(a)
{
a=a/10;
nrcif++;
p=p*10;
}
p=p/10;
a=x%10*p+x/10;
perm=1;
while(a!=x)
{
a=a%10*p+a/10;
perm++;
}
if(perm<nrcif)
cout<<x<<" ",nr++;
if(nr%2==0 && nr!=0)
cout << endl;

}
if(nr == 0)
cout << 0;
return 0;
}

Bilet 23
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("numere.in");

int n, nrv, r;

int main()
{
cin >> n;
///792 reprezintă numărul de cifre folosite pentru un volum complet
nrv = n/792;
r=n%792;
if(r==0) ///ultimul volum este complet
cout<<nrv<<' '<<300;
else
if(r <= 9)
{
cout << nrv+1 << ' ' << r;
}
else if(r-9 <= 180)
{
if((r-9)%2==0)
cout << nrv+1 << ' ' << 9+(r-9)/2;
else
cout << "IMPOSIBIL";
}
else
{
if((r-189)%3==0)
cout << nrv+1 << ' ' << 99 + (r-189)/3;
else
cout << "IMPOSIBIL";
}

Bilet 24
#include <fstream>
using namespace std;
ifstream fin("eur.in");
ofstream fout("eur.out");
int b[101],v[101],n,suma,e,S;
int main()
{
fin>>S>>n>>e;
v[1]=1;
for(int i=2;i<=n;i++)
{
v[i]=v[i-1]*e;
}
for(int i=n;i>=1;i--)
{
b[i]=S/v[i];
S=S%v[i];
if(b[i]!=0)
fout<<b[i]<<" bancnote cu valoarea "<<v[i]<<endl;
suma=suma+b[i];
}
fout<<suma;
return 0;
}

Bilet 25
#include <bits/stdc++.h>

using namespace std;

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

int v[10000], n;

int main()
{
while(fin>>n)
{
if(n<=9999)
v[n]=1;
}
for(n=9999; n>=0; n--)
if(v[n]==0)
fout<<n<<' ';

return 0;
}

Bilet 26
#include <bits/stdc++.h>
using namespace std;
ofstream fout("munte.txt");
int c1, c2, c3, c4, c5, k;
int main()
{
for(c1=1;c1<=5;c1++)
for(c2=c1+1;c2<=6;c2++)
for(c3=c2+1;c3<=7;c3++)
for(c4=c3+1;c4<=8;c4++)
for(c5=c4+1;c5<=9;c5++)
{
fout<<c1<<c2<<c3<<c4<<c5<<c4<<c3<<c2<<c1<<endl;
k++;
}
fout<<endl<<k;
return 0;
}

Bilet 27
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("mat.in");
ofstream fout("mat.out");
int n, m, a[32][32],vmin,vmax,nr;

int main()
{
fin >> n >> m;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
fin >> a[i][j];
vmax = 0; nr = 0;
///se parcurge matricea pe coloane
///se introduce o linie noua ce va contine minimul coloanelor
for(int j=1; j<=m; ++j)
{
vmin = a[1][j];
for(int i=1; i<=n; ++i)
{
if(a[i][j] < vmin)
vmin = a[i][j];
if(a[i][j] > vmax)
vmax = a[i][j];
}
a[n+1][j]=vmin;
cout << vmin << ' ';
}
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
if(a[i][j] == vmax && a[i][j] != a[n+1][j])
{
a[i][j]=a[n+1][j];
nr++;
}
if(nr!=0) {
for(int i=1; i<=n; ++i) {
for(int j=1; j<=m; ++j)
fout << a[i][j] << ' ';
fout << '\n';
}
fout << nr;
}
return 0;
}

Bilet 28
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
ifstream fin("numere.in");
ofstream fout("numere.out");

int n, v[10001], a[101][101], k, nl, nr;

int main()
{
fin >> n;
for(int i=1; i<=n; ++i)
fin >> v[i];
k = sqrt(n)/2; ///numarul de chenare(+1 daca nl este impar)
nl = sqrt(n); ///numarul de linii
nr=1;
if(nl%2 == 1)
k++;
///parcurgem fiecare chenar
for(int c=1; c<=k ;++c) {
///coloana din stanga chenarului
for(int i=c; i<=nl-c+1; ++i)
a[i][c] = v[nr++];
///linia de jos a chenarului
for(int j=c+1; j<=nl-c+1; ++j)
a[nl-c+1][j] = v[nr++];
///coloana din dreapta chenarului
for(int i=nl-c; i>=c; i--)
a[i][nl-c+1] = v[nr++];
///linia de sus a chenarului
for(int j=nl-c; j>=c+1; --j)
a[c][j] = v[nr++];
}
for(int i=1; i<=nl; ++i) {
for(int j=1; j<=nl; ++j)
fout << a[i][j] << ' ';
fout << '\n';
}
return 0;
}

Bilet 29
#include <fstream>
#include<cstring>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
char s[256],*cuv,s1[300], s2[256][100],ct, aux[256];

bool hasBeen(char s[256]) {


strcat(s, " ");
for(int i=1; i<=ct; ++i)
if(strstr(s2[i], s))
return false;
return true;
}

int main()
{
ct=1;
while(fin.getline(s,256))
{
cuv=strtok(s," .,;:-?!");
while(cuv)
{
strcpy(s1,cuv);
cuv=strlwr(cuv);
if(strstr(cuv,"ate"))
{
strcpy(aux, cuv);
if(hasBeen(aux))
{
fout<<s1<<'\n';
strcat(s2[ct], aux);
strcat(s2[ct], " ");
}
}

cuv=strtok(NULL," .,;:-?!");
}
fin.get();
ct++;
}
return 0;
}

Bilet 30
#include <bits/stdc++.h>

using namespace std;


ofstream fout("date.out");
int n, x, y, i, d, d2;
int main()
{
cin>>n;
for(i=1;i*i<=n;i++)
{
if(n%i==0)
{
d=i;
d2=n/d;
if((d+d2)%2==0)
{
x=(d+d2)/2;
y=(d-d2)/2;
fout<<x<<" "<<y<<endl;
fout<<-x<<" "<<y<<endl;
fout<<x<<" "<<-y<<endl;
fout<<-x<<" "<<-y<<endl;
}
}
}
return 0;
}

You might also like