Probleme Info Atestat
Probleme Info Atestat
Probleme Info Atestat
#include <iostream>
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;
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>
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 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>
Bilet 16
#include <bits/stdc++.h>
}
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");
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>
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 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];
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>