http://clasa11info.wikispaces.com/Atestat
http://info12.wikispaces.com/file/view/atestat2012_Cpp_solutii.pdf
Bilet 1http://info12.wikispaces.com/file/view/atestat2012_Cpp_solutii.pdf
#include<iostream>Bilet 2. Cifra de control
#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 i,n,a,b,A=0,B=1,auxA,auxB;
ifstream f("date.in");
f>>n;
for(i=1;i<=n;i++)
{ f>>a>>b;
auxA=A*b+a*B;
auxB=B*b;
A=auxA;
B=auxB;
}
int c=cmmdc(A,B);
A=A/c;
B=B/c;
cout<<A<<"/"<<B;
}
#include<iostream>Bilet 3
using namespace std;
int suma(int n)
{int s=0;
while(n)
{s=s+n%10;
n=n/10;
}
return s;
}
int control(int n)
{int s;
s=suma(n);
while(n>9)
{n=s;
return control(n);}
return s;
}
int main()
{int n;
cin>>n;
cout<<control(n);
}
#include<iostream>Bilet 4
using namespace std;
int main()
{int a,b,n,c,A;
cin>>a>>b>>n;
while(n)
{a=a*10;
c=a/b;
A=b*c;
a=a-A;
cout<<c;
n--;}
}
#include<iostream>Bilet 5
using namespace std;
int prim(int n)
{int ok=1,d;
for(d=2;d<=n/2;d++)
if(n%d==0)
ok=0;
return ok;
}
int invers(int n)
{int r=0;
while(n)
{r=r*10+n%10;
n=n/10;}
return r;
}
int main()
{int n;
for(n=100;n<=999;n++)
if(prim(n) && prim(invers(n)))
cout<<n<<endl;
}
#include<iostream>Bilet 5
using namespace std;
int main()
{int n,ok,i,m,s;
cin>>n;
ok=0;
i=n;
while(i>=n/2 && ok==0)
{m=i;
s=0;
while(m)
{s=s+m%10;
m=m/10;}
if(n==i+s)
ok=1;
i=i-1;
}
if(ok==1)
cout<<"DA";
else cout<<"NU";
}
#include<iostream>Bilet 6
using namespace std;
int suma(int n)
{int s=0;
while(n)
{s=s+n%10;
n=n/10;
}
return s;
}
int main()
{int n;
cin>>n;
int i=n,ok=1;
while(i>0)
{if(i+suma(i)==n)
ok=0;
i--;}
if(ok==0)
cout<<"DA";
else cout<<"NU";
}
#include<iostream>Bilet 7
using namespace std;
int nrcif(int n)
{int i=0;
while(n)
{ i++;
n=n/10;}
return i;}
int main()
{int n,i=1,s=0;
cin>>n;
for(i=1;i<=n;i++)
s=s+nrcif(i);
cout<<s;
}
#include<iostream>Bilet 8
using namespace std;
int main()
{int aa,bb,cc,a,b;
cin>>a>>b;
aa=bb=1;
cc=aa+bb;
while(cc<a)
{ aa=bb;
bb=cc;
cc=aa+bb;
}
if(cc>a)
{ cout<<"NU";return 0;}
if(cc==a)
if(bb+a==b)
cout<<"DA";
}
#include<iostream>Bilet 9
using namespace std;
int suma(int i, int n, int &k)
{int s=0,j;
for(j=i;j<n;j++)
if(s<n)
s=s+j;
else break;
k=j-1;
return s;
}
int main()
{int n,i,j,ok,k=0;
cin>>n;
for(i=1;i<n;i++)
if(suma(i,n,k)==n)
{for(j=i;j<=k;j++)
cout<<j<<" ";
cout<<endl;}
}
#include<iostream>Bilet 10
using namespace std;
int prim(int n)
{int ok=1,d;
if(n<2)
return 0;
if(n==2)
return 1;
for(d=2;d<=n/2;d++)
if(n%d==0)
ok=0;
return ok;
}
int main()
{int n,i,j,ok=1;
cin>>n;
int nn=n;
while(prim(nn))
nn=nn/10;
if(nn)
ok=0;
if(ok==0)
cout<<"NU";
else{
cout<<"DA"<<endl;
while(n/10)
{
cout<<n/10<<endl;
n=n/10;
}
}
}
#include<iostream>Bilet 11
using namespace std;
int prim(int n)
{int ok=1,d;
if(n<2)
return 0;
for(d=2;d<=n/2;d++)
if(n%d==0)
ok=0;
return ok;
}
int main()
{unsigned int n,i,j,ok=1;
cin>>n;
for(i=0;i<=n;i++)
if(prim(n-i) || prim(n+i))
{cout<<n-i;break;}
}
#include<iostream>Bilet 12
#include<fstream>
using namespace std;
int cautare(int v[], int n, int x)
{int i,ok=0;
for(i=1;i<=n;i++)
if(v[i]==x)
ok++;
return ok;}
int main()
{ifstream f("date");
int n,a,b,c=-1,v[100],i,j=0,max=0,ok,p;
f>>n;
for(i=1;i<=n;i++)
{f>>v[i];
if(v[i]>max)
max=v[i];}
a=0;
b=1;
while(c<=max)
{c=a+b;
p=cautare(v,n,c);
while(p)
{cout<<c<<" ";
j++;
p--;}
c=a+b;
a=b;
b=c;
}
cout<<endl<<j<<" numere";
}
#include<iostream>Bilet 13
#include<fstream>
using namespace std;
int cautare(int a[], int n, int x)
{int i,ok=0;
for(i=1;i<n;i++)
if(a[i]==x)
ok++;
return ok;}
void eliminare(int a[],int &n, int i)
{int j;
for(j=i;j<n;j++)
a[j]=a[j+1];
n--;}
int main()
{int a[100],n,i,j,ok=1;
ifstream f("date");
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
for(i=1;i<n;i++)
for(int j=i+1;j<=n;j++)
if(a[i]==a[j])
ok=0;
if(ok==1)
{cout<<"DA"<<endl;
for(i=1;i<=n;i++)
cout<<a[i]<<" ";}
else {cout<<"NU"<<endl;
for(i=2;i<=n;i++)
if(cautare(a,i,a[i]))
{eliminare(a,n,i);
i--;}
for(i=1;i<=n;i++)
cout<<a[i]<<" ";}
}
#include<iostream>Bilet 14
#include<fstream>
using namespace std;
int main()
{ifstream f("date");
int n,m,a[100],b[100],min=INT_MAX;
f>>n;
for(int i=1;i<=n;i++)
{ f>>a[i];
if(a[i]<min)
min=a[i];}
f>>m;
for(int i=1;i<=m;i++)
{ f>>b[i];
if(b[i]<min)
cout<<b[i]<<" ";
}
}
#include<fstream>Bilet 15
#include<iostream>
using namespace std;
int main()
{int x[20],t=0,s,i=0;
char a[100],b[100];
int r;
ifstream f("date");
f>>a>>b;
int aa=strlen(a)-1;
int bb=strlen(b)-1;
while(aa>=0 && bb>=0)
{r=a[aa]-'0'+b[bb]-'0'+t;
i++;
x[i]=r%10;
t=r/10;
aa--;
bb--;}
while(aa>=0)
{ r=a[aa]-'0'+t;
t=r/10;
i++;
x[i]=r%10;
aa--;}
while(bb>=0)
{ r=b[bb]-'0'+t;
t=r/10;
i++;
x[i]=r%10;
bb--;}
for(int j=i;j>=1;j--)
cout<<x[j];
}
#include<fstream>Bilet 16 - tabloul de frecvenţe pentru numere negative (ex. f[-6] ???) // sau cu functia apare
#include<iostream>
using namespace std;
int main()
{ifstream f("date");
int n,a[100],b[100],i,j,aa=1,bb=1,x,c[100],k;
f>>n;
f>>a[1];
while(f>>x)
if(x<a[aa])
break;
else {aa++;
a[aa]=x;}
b[1]=x;
while(f>>x)
{bb++;
b[bb]=x;}
/*for(i=1;i<=aa;i++)
cout<<a[i]<<" ";
cout<<endl;
for(i=1;i<=bb;i++)
cout<<b[i]<<" ";*/
i=j=1;
k=1;
while(i<=aa && j<=bb)
if(a[i]<b[j])
{c[k]=a[i];i++;k++;}
else {c[k]=b[j];j++;k++;}
while(i<=aa)
{c[k]=a[i];i++;k++;}
while(j<=bb)
{c[k]=b[j];j++;k++;}
for(i=1;i<k;i++)
cout<<c[i]<<" ";
}
#include<fstream>Bilet 17 - tabloul de frecvenţe pentru numere negative (ex. f[-6] ???) / sau cu functia apare
#include<iostream>
using namespace std;
int main()
{ifstream f("date");
int n,i,j,a[100],v[100]={0},maxf=0,maxv=0;
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
for(i=1;i<=n;i++)
v[a[i]]++;
for(i=1;i<=n;i++)
if(a[i]>maxv)
maxv=a[i];
for(i=1;i<=maxv;i++)
if(v[i]>maxf)
maxf=v[i];
for(i=1;i<=maxv;i++)
if(v[i]==maxf)
cout<<i<<" ";
}
#include<fstream>Bilet 18
#include<iostream>
using namespace std;
int main()
{ifstream g("date");
int n,i,j,v[100],f[100]={0},w[100];
g>>n;
for(i=1;i<=n;i++)
g>>v[i];
for(i=1;i<=n;i++)
f[v[i]]++;
for(i=1;i<=n;i++)
w[i]=f[v[i]];
for(i=1;i<=n;i++)
cout<<v[i]<<" ";
cout<<endl;
for(i=1;i<=n;i++)
cout<<w[i]<<" ";
}
#include<iostream>Bilet 19
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{int v[100][100],n,i,j,a,b,c;
ifstream f("date");
f>>n;
a=b=1;
v[1][1]=v[1][2]=1;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(v[i][j]==0)
{c=a+b;
v[i][j]=c;
a=b;
b=c;}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
cout<<setw(6)<<v[i][j];
cout<<endl;}
}
#include<iostream>Bilet 20
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{int a[100][100],n,i,j,b,c,s=0;
ifstream f("date");
f>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
f>>a[i][j];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i+j<=n && i<j && a[i][j]%2==1)
s=s+a[i][j];
cout<<s;
}
#include<iostream>Bilet 21
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{char a[100],b[100],i,j,n;
ifstream f("date");
f>>a;
strcpy(b,a);
n=strlen(a);
for(i=0;i<n;i++)
if(a[i]!=a[i-1])
{strcpy(a+i,a+i+1);
cout<<a<<endl;
strcpy(a,b);}
}
#include<iostream>Bilet 22
#include<fstream>
#include<iomanip>
using namespace std;
int cautare(int v[], int n, int x)
{int i,ok=0;
for(i=1;i<=n;i++)
if(v[i]==x)
ok++;
return ok;}
int main()
{int n,m=0,i,j,c,a[100]={0};
ifstream f("date");
f>>n;
while(n)
{c=n%10;
if(cautare(a,m,c)==0)
{m++;
a[m]=c;}
n=n/10;
}
for(i=1;i<m;i++)
for(j=i+1;j<=m;j++)
if(a[i]<a[j])
swap(a[i],a[j]);
for(i=1;i<=m;i++)
cout<<a[i];
}
#include<iostream>Bilet 23
#include<fstream>
#include<iomanip>
using namespace std;
int prim(int n)
{int ok=1,d;
if(n<2)
return 0;
if(n==2)
return 1;
for(d=2;d<=n/2;d++)
if(n%d==0)
ok=0;
return ok;
}
int main()
{int n,m,ok=0,nr=0,i;
ifstream f("date");
f>>n>>m;
for(i=n+1;i<m;i++)
if(prim(i))
{ok=1;
nr++;
if(nr>10)
{cout<<endl<<i<<" ";nr=0;}
else {cout<<i<<" ";}
}
if(ok==0)
cout<<"Niciun numar prim";
}
#include<iostream>Bilet 24. Recursiv, dar cu repetitivă!
#include<fstream>
using namespace std;
void descompunere(int x)
{int d=2,p;
while(x>1)
{p=0;
while(x%d==0)
{x=x/d;
p++;}
cout<<"Factorul "<<d<<" la puterea "<<p<<endl;
d++;
}
}
int main()
{int n;
ifstream f("date");
f>>n;
descompunere(n);
}
#include<iostream>Bilet 25. Căutare binară. Cea mai eficientă?
#include<fstream>
using namespace std;
void g(int n)
{int i;
if(n)
{g(n-1);
for(i=1;i<=n;i++)
cout<<i<<" ";
cout<<endl;
}
}
int main()
{int n;
ifstream f("date");
f>>n;
g(n);}
#include<iostream>
#include<fstream>
using namespace std;
int binar(double a[],double x, int st, int dr)
{int m;
if(st>dr)
return 0;
m=(st+dr)/2;
if(a[m]>x)
{return binar(a,x,st,m-1);}
else if(a[m]<x) {return binar(a,x,m+1,dr);}
else return m;
}
int main()
{int n,i,j;
double a[100],x;
ifstream f("date");
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
f>>x;
cout<<binar(a,x,1,n);
}