0% found this document useful (0 votes)
40 views21 pages

Sub3 Bac

The document contains 20 coding problems that involve reading input from files, performing calculations, and outputting results. Each problem contains C++ code to solve a programming task related to processing numeric data.

Uploaded by

Quiet Sounds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views21 pages

Sub3 Bac

The document contains 20 coding problems that involve reading input from files, performing calculations, and outputting results. Each problem contains C++ code to solve a programming task related to processing numeric data.

Uploaded by

Quiet Sounds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Sub3 Bac

T1 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,c;
int main() {
cin>>b>>a;
cout<<a<<' '<<b<<' ';
while(a!=b)
{
int aux=b;
b=3*b-a;
a=aux;
cout<<b<<' ';
}
return 0;
}

T2 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int v[4],x,t;
int main() {
while(f>>x)
{
if(x%10==0 && x/10%10==2)
{
if(t==3) {
int poz=1;
if(v[2]<v[poz])
poz=2;
if(v[poz]>v[3])
poz=3;
if(v[poz]<x)
v[poz]=x;
}
else v[++t]=x;

}
}
for(int i=1;i<3;++i)
for(int j=i+1;j<=3;++j)
if(v[i]>v[j])
{
int aux=v[i];
v[i]=v[j];
v[j]=aux;
}
cout<<v[1]<<' '<<v[2]<<' '<<v[3];
return 0;
}

T3 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int poz1,poz2,x,nr;
int main() {
while(f>>x)
{
++nr;
if(x<0)
{
if(poz1==0)
poz1=nr;
poz2=nr;
}
}
cout<<max(nr-poz1+1,poz2);
return 0;
}

T4 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,ok,l=1;
int main() {
f>>a;
while(f>>b)
{
if(a==b)
++l;
else
{
if(l==2)
cout<<a<<' ';
l=1;
}
a=b;
}
if(l==2)
cout<<b;
return 0;
}

T5 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int s,smax=-1000000000,x;
int main() {
while(f>>x)
{
if(s<0)
s=0;
s+=x;
if(s>smax)
smax=s;
}
cout<<smax;
return 0;
}
T6 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int p1,p2;
int main() {
cin>>p1>>p2;
for(int x1=9;x1>=1;x1--)
if(p1%x1==0 && p1/x1<=9)
{
for(int mij=9;mij>=0;mij--)
{
for(int x2=9;x2>=1;x2--)
if(p2%x2==0 && p2/x2<=9)

cout<<x1<<p1/x1<<mij<<mij<<mij<<x2<<p2/x2<<'\n';
}
}
return 0;
}

T7 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int x,s,smin=1000000000;
int main() {
while(f>>x)
{
if(s>0)
s=0;
s+=x;
if(s<smin)
smin=s;
}
cout<<smin;
return 0;
}

T8 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int x,poz[10],fr[10],maxi;
int main() {
int nr=0;
while(f>>x)
{
++nr;
fr[x%10]++;
poz[x%10]=nr;
}
for(int i=0;i<=9;++i)
if(fr[i]>maxi)
maxi=fr[i];
for(int i=0;i<=9;++i)
if(fr[i]==maxi)
cout<<poz[i]<<' ';
return 0;
}

T9 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int x,l,lmax,nr,a;
int main() {
f>>a;
while(f>>x)
{
if(x%a==0)
++l;
else
{
if(l>lmax)
lmax=l,nr=1;
else if(l==lmax)
nr++;
l=0;
}
}
if(l>lmax)
lmax=l,nr=1;
else if(l==lmax)
nr++;
cout<<lmax<<' '<<nr;
return 0;
}

T10 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,r,ok,l,lmax,rmax;
int main() {
f>>a>>b;r=a-b;a=b;
l=2;
while(f>>b)
{
if(a-b==r)
++l;
else
{
if(l>lmax)
lmax=l,rmax=r;
else
if(l==lmax && rmax<r)
rmax=r;
l=2;
r=a-b;

}
a=b;
}
if(l>lmax)
lmax=l,rmax=r;
else
if(l==lmax && rmax<r)
rmax=r;
cout<<-rmax;
return 0;
}

T11 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,fr;
int main() {
f>>a;fr=1;
while(f>>b)
{
if(a==b)
fr++;
else
{
cout<<a<<' '<<fr<<' ';
fr=1;
}
a=b;
}
cout<<b<<' '<<fr;
return 0;
}

T12 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int x,par,imp;
int main() {
cin>>x;
if(x%2==0)
par=1;
else imp=1;
while(x>=1)
{
cout<<x<<' ';
if(x<=10)
x--;
else
{
if(imp)
x--,imp=0,par=1;
else
x/=2,imp=1,par=0;
}
}
return 0;
}

T13 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int x;
int main() {
cin>>x;
while(x>=1)
{
cout<<x<<' ';
x/=2;
}
return 0;
}

T14 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int x,v[4],t;
int main() {

while(f>>x)
{
if(x%10==0 && x/10%10==2)
{
if(t<3)
v[++t]=x;
else
{

int maxi=1;
if(v[maxi]<v[2])
maxi=2;
if(v[maxi]<v[3])
maxi=3;
if(v[maxi]>x)
v[maxi]=x;
}
}
}

for(int i=1;i<3;++i)
for(int j=i+1;j<=3;++j)
if(v[i]>v[j])
{int aux=v[i];v[i]=v[j];v[j]=aux;}
cout<<v[1]<<' '<<v[2]<<' '<<v[3];
return 0;
}

T15 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int p1,p2;
int main() {
cin>>p1>>p2;int nr=0;
for(int x=1;x<=9;++x)
if(p1%x==0 && p1/x<=9)
{
for(int mij=0;mij<=9;++mij)
for(int y=1;y<=9;++y)
if(p2%y==0 && p2/y<=9)
cout<<x<<p1/x<<mij<<mij<<mij<<y<<p2/y<<'\n',++nr;
}

return 0;
}

T16 2020

T17 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,fr[10001],a,b;
int main() {
f>>n;int nr=0;
for(int i=1;i<=n;++i)
f>>a,fr[a]=1;

while(f>>a>>b)
{
bool ok=1;
for(int i=a;i<=b;++i)
if(fr[i])
{ok=0;break;}
nr+=ok;
}
cout<<nr;
return 0;
}

T18 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,a,b,l,lmax,nr;
int main() {
f>>a;
if(a%10==0)
l=1;
while(f>>b)
{
if(b%10==0)
++l;
else
{
if(l>lmax)
lmax=l,nr=1;
else
if(l==lmax)
++nr;

l=0;
}
a=b;
}
if(l>lmax)
lmax=l,nr=1;
else
if(l==lmax)
++nr;
cout<<lmax<<' '<<nr;
return 0;
}

T19 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b;
int main() {
f>>a;
if(a%2==0)
cout<<a<<' ';
while(f>>b)
{
if(b!=a && b%2==0)
cout<<b<<' ';
a=b;
}
return 0;
}

T20 2020
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,s,smax;
int main() {
f>>a;
s=a;
while(f>>b)
{
if(a%2==b%2)
s+=b;
else
{
if(s>smax)
smax=s;
s=b;
}
a=b;
}
if(s>smax)
smax=s;
cout<<smax;
return 0;
}

T11 2021
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,nr;
int main() {
f>>a>>b;
nr=(b-a)/2;
cout<<b<<' '<<a<<' ';
nr--;
while(nr>0)
{
a=a-2*nr;
cout<<a<<' ';
nr--;
}
return 0;
}

T6 2021
#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int poz1,poz2,poz3;
int main() {
int x;int nr=0;
while(f>>x)
{
++nr;
if(x<0)
{
if(!poz1)
poz1=nr;
else
if(!poz2)
poz2=nr;
else poz3=nr;
}
}
cout<<max(poz2-1,max(poz3-1-poz1,nr-poz2));
return 0;
}

V6.4#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,b,nr=1;
int main() {
f>>a;
while(f>>b)
{
if(a==b)
++nr;
else
{
cout<<a<<' '<<nr<<' ';
nr=1;
}
a=b;
}
cout<<a<<' '<<nr;
return 0;
}

V8.4 void sub(int n,int m,int a[],int b[])


{
int i=0,j=0,par=0,imp=0,nr=0;
if(a[0]<b[0])
cout<<a[0]<<' ',par=1,i++,nr=a[0];
else cout<<b[0]<<' ',imp=1,j++,nr=b[0];
while(i<n && j<m)
{
if(par){
if(nr<b[j])
cout<<b[j]<<' ',imp=1,par=0,nr=b[j],j++;
else j=m;
}
else
{
if(nr<a[i])
cout<<a[i]<<' ',par=1,imp=0,nr=a[i],++i;
else i=n;
}
}
if(par && b[j+1]>nr)
cout<<b[j+1];
if(imp && a[i+1]>nr)
cout<<a[i+1];
}
V9.4#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int a,fr[1000],m1,m2;
int main() {
while(f>>a)
if(a<1000)
fr[a]=1;
for(int i=999;i>=100;--i)
if(!fr[i] && (!m1 || !m2))
m2=m1,m1=i;
else
if(m1 && m2)
break;
cout<<m2<<' '<<m1;
return 0;
}

V10.4#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int nr,c,pr,fr[10000],s[10001];
int main() {
while(f>>nr>>c>>pr)
s[nr]+=c*pr;
for(int i=1;i<=9999;++i)
if(s[i])
cout<<i<<' '<<s[i]<<'\n';
return 0;
}

V11 3#include <iostream>


#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,maxi,x;
int main() {
f>>n;
for(int i=1;i<=n;++i)
{
f>>x;
if(x>maxi)
maxi=x;
cout<<maxi<<' ';
}
return 0;
}

V12 3.#include <iostream>


#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,a[101],b[101],m;
int main() {
cin>>n;
for(int i=1;i<=n;++i)
cin>>a[i];
cin>>m;
for(int i=1;i<=m;++i)
cin>>b[i];

int i=1,j=1;
while(i<=n && j<=m) {

if(a[i]<b[j])
{
// cout<<a[i]<<'\n';
if(a[i]%5==0)
cout<<a[i]<<' ';
i++;
}
else
if(b[j]<a[i])
{
// cout<<b[j]<<'\n';
if(b[j]%5==0)
cout<<b[j]<<' ';++j;
}
else
i++,j++;
// cout<<i<<' '<<j<<'\n';
}
while(i<=n)
{
if(a[i]%5==0)
cout<<a[i]<<' ';
i++;
}
while(j<=m)
{
if(b[j]%5==0)
cout<<b[j]<<' ';
j++;
}
return 0;
}

V13 3.#include <iostream>


#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n, k;

int main() {
cin >> n;
k = 1;
while (k * (k + 1) < 2 * n)
k++;
cout<<k+1-(n-k*(k-1)/2);

return 0;
}

V20 3.#include <iostream>


#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n, m,a[1001],b[1001];

int main() {
cin>>n;int x;
for(int i=1;i<=n;++i)
cin>>x,a[x]=1;
cin>>m;
for(int i=1;i<=m;++i)
cin>>x,b[x]=1;
for(int i=1;i<=1000;++i)
if(a[i] && b[i])
cout<<i<<' ';
return 0;
}

V25#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
float x,a,b;
int main() {
cin>>x;
for(int i=1;;i++)
if(x*i==int(x*i))
{cout<<i*x<<' '<<i;break;}
return 0;
}

V29#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,m,a[1001],b[1001],s;
int main() {
f>>n>>m;
for(int i=1;i<=n;++i)
f>>a[i];
for(int i=1;i<=m;++i)
f>>b[i];
int poz=1,ok=1,nr=1;
while(ok && nr<=m)
{
// cout<<nr<<'\n';
for(int i=poz;i<=n;++i)
{
s+=a[i];
if(s==b[nr])
{++nr,s=0;poz=i+1;break;}
else
if(s>b[nr])
{ok=0;break;}
}
}
if(ok)
cout<<"DA";
else cout<<"NU";
return 0;
}

V30#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,nr,a;
float v[101];
int main() {
f>>n;
for(int i=1;i<=n;++i)
{
f>>v[i];
if(a==0)
nr=1,a=int(v[i]);
else
{
if(a+1<v[i])
nr++,a=int(v[i]);
}
}
cout<<nr;
return 0;
}
V31#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,a,b;
int main() {
int x,y;bool ok=1;
f>>n>>x>>y;
for(int i=2;i<=n;++i)
{
f>>a>>b;
if(a>y || b<x)
ok=0;
else
{
x=max(x,a);
y=min(y,b);
}
}
if(ok)
cout<<x<<' '<<y;
else cout<<0;
return 0;
}

V32#include <iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<fstream>
#include<algorithm>

using namespace std;


ifstream f("fisier.in");
//ofstream g("fisier.out");
int n,min1=100,min2=100,x;
int main() {
while(f>>x)
{
if((x>-100 && x<-9) || (x>9 &&x<100))
{
if(min1<min2)
{
if(min2>x)
min2=x;
}
else
if(min1>x)
min1=x;
}
}
if(min1==100 || min2==100)
cout<<0;
else
cout<<min1<<' '<<min2;
return 0;
}

You might also like