0% found this document useful (0 votes)
86 views13 pages

1) Problema 3072 (60 PCT, 2 Raspunsuri Gresite) Cod:: #Include

The document contains code snippets for solving various competitive programming problems. The problems involve tasks like: 1) Dividing a number into three parts based on its remainder when divided by 3. 2) Calculating the nth Fibonacci and Icannobif numbers and their number of divisors. 3) Exclusive OR'ing an array of numbers to find the result. 4) Padding a number with leading zeros to make it have a given number of digits while preserving its value modulo a given base.

Uploaded by

Mara Spataru
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)
86 views13 pages

1) Problema 3072 (60 PCT, 2 Raspunsuri Gresite) Cod:: #Include

The document contains code snippets for solving various competitive programming problems. The problems involve tasks like: 1) Dividing a number into three parts based on its remainder when divided by 3. 2) Calculating the nth Fibonacci and Icannobif numbers and their number of divisors. 3) Exclusive OR'ing an array of numbers to find the result. 4) Padding a number with leading zeros to make it have a given number of digits while preserving its value modulo a given base.

Uploaded by

Mara Spataru
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/ 13

1) Problema 3072 (60 pct, 2 raspunsuri gresite)

Cod:

#include <bits/stdc++.h>
using namespace std;

int n, rest;
int main()
{
cin>>n;
rest=n%3;
n/=3;
if(rest==0) cout<<n<<" "<<n<<" "<<n;
if(rest==1) cout<<n<<" "<<n<<""<<n+1;
if(rest==2) cout<<n<<" "<<n+1<<" "<<n+1;

return 0;
}

2) Problema 1956 (35 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int n,nr0,nr1,nr2,nr_0,nr_1,nr_2,ogl0,ogl1,fib,icc,i,a,b,d,nrdivfib,nrdivicc,p;
int main()
{
fin>>p>>n;
fin.close();
nr0=1;
nr1=1;
for(i=3;i<=n;i++)
{
nr2=nr1+nr0;
nr0=nr1;
nr1=nr2;

}
fib=nr2; //al n-lea termen fibonacci

nr_0=1;
nr_1=1;
for(i=3;i<=n;i++)
{
ogl0=0,ogl1=0;
a=nr_0;
b=nr_1;
while(a!=0)
{
ogl0=ogl0*10+a%10;
a/=10;
}
while(b!=0)
{
ogl1=ogl1*10+b%10;
b/=10;
}

nr_2=ogl0+ogl1;
nr_0=nr_1;
nr_1=nr_2;

}
icc=nr_2; //al n-lea iccanobif termen

for(d=1;d<=fib;d++) //nr divizori fibonacci


if(fib%d==0) nrdivfib++;
for(d=1;d<=icc;d++) //nr divizori iccanobif
if(icc%d==0) nrdivicc++;

if(p==1) fout<<fib<<" "<<nrdivfib;


else if(p==2) fout<<icc<<" "<<nrdivicc;
else fout<<fib<<" "<<nrdivfib<<endl<<icc<<" "<<nrdivicc;

fout.close();
return 0;
}

3) Problema 2280 (100 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int n,i;
unsigned long long rez,x;

int main()
{
fin>>n;
rez=0;
for (i=1;i<=n;i++)
{
fin>>x;
rez=rez^x;
}
fout<<rez;
fin.close();
fout.close();
return 0;
}
4) Problema 1915 (100 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

long long n,b,r,k,x,s,i,nr ;


int main()
{
cin>>n>>b>>r;
k=0,x=r;
while(x!=0) //numarul cifrelor lui r
{
k++;
x/=10 ;
}
// afisare
if(k>n)cout<<-1;
else if(k==n)cout<<r;
else
{
s=1;
for (i=2;i<=n;i++) s=(s*10)%b;
if (s<=r) nr=r-s;
else nr=b-s+r;
if (nr==0)
{
cout<<1 ;
for (i=1;i<=n-1;i++) cout<<0;
}
else
{
k=0;
x=nr;
while (x!=0)
{
k++;
x/=10;
}
cout<<1;
for (i=1;i<=n-k-1;i++) cout<<0 ;
cout<<nr ;
}
}
return 0;
}

5) Problema 1723 (100 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

long long int P,N,nrp,aux,y=10,T,nrcif,M=1,i;


int main()
{
fin>>P>>N;
fin.close();
nrp=P*(P+1)/2,aux=nrp; //nr prb
while (aux)
{
nrcif++;
aux/=10;
}
for (i=1;i<nrcif;i++,y*=10)
T+=(i*(y-y/10));
T+=(nrcif*(nrp-y/10+1));
fout<<T<<endl;
while (M*(M+1)/2<N)
M++;
fout<<M;
fout.close();
return 0;
}

6) Problema 1073 (100 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int n,k;
int main()
{
fin>>k>>n;
fin.close();
if(k%2==0)
fout<<k*5<<" "<<k*5<<" "<<k*5-1<<" "<<k*5-2<<" "<<k*5-3<<" "<<k*5-4;
//constructia liniei de la dr la stg pt nr pare
else
fout<<k*5-4<<" "<<k*5-3<<" "<<k*5-2<<" "<<k*5-1<<" "<<k*5<<" "<<k*5;
//constr liniei de la stg la dr pt nr impare
fout<<endl;
if(n%5==0) fout<<n/5<<endl;
else fout<<n/5+1<<endl;
if(n%10==0) fout<<"A"<<" "<<"B";
else if (n%10==1) fout<<"A";
else if(n%10==2) fout<<"B";
else if(n%10==3 || n%10==9) fout<<"C";
else if(n%10==4 || n%10==8) fout<<"D";
else if(n%10==5) fout<<"E"<<" "<<"F";
else if(n%10==6) fout<<"F";
else fout<<"E";
fout.close();

return 0;
}

7) Problema 1072 (100 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int n,fr[10],i,j,k,m;
char s,f[1001];

int main()
{
fin>>n;
fin.get();
for(i=0;i<n;i++)
{
fin>>s;
if(s>='a' && s<='z') //cautam literele
{
s-=32; //le transformam in litere mari si le afisam
fout<<s;
}
else fr[(int)(s-'0')]=1;
}
fout<<endl;

for(i=1;i<=9;i++)
if(fr[i]==1) break;
if(fr[0]==1) {fout<<i;fr[i]=0;} //daca 0 este prima cifra, o afisam pe cea de
pe poz i
for(i=0;i<=9;i++)
if(fr[i]==1)fout<<i;

fout.close();
return 0;
}

8) Problema 1060 (70 puncte, nu am rezolvat cerinta D)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int n,pcules,x,nr,nrt;

int main()
{
fin>>n>>x;
fin.close();
pcules=n-n/2; //nr porumbi culesi de primul agri
fout<<pcules<<endl;
while(n)
{
nr++;
n/=2;
}
fout<<nr<<endl; //nr agri
while(x%2==0) //daca x e pe o pozitie para nu va fi cules
{
x/=2;
nrt++; //numar treceri
}
fout<<nrt+1<<endl;
fout.close();
return 0;
}

9) Problema 1051 (100 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int n,lgi,a,b,i,s,lga,lgb,xa,xb;

int main()
{
fin>>n;
fin>>a;
lga=a;xa=1;s=a;
for(i=2;i<=n;i++)
{
fin>>a;
if(lga<a) //lg max fragmente ana
{
lga=a;
xa=1;
}
else if(lga==a) xa++;
s+=a;
}
fin>>b;
lgb=b;xb=1;s+=b;
for(i=2;i<=n;i++)
{
fin>>b;
if(lgb<b) //lg max fragmente bogdan
{
lgb=b;
xb=1;
}
else if(lgb==b) xb++;
s+=b; //suma fragmentelor
}
fin.close();
lgi=s/n; //lg betelor
fout<<lgi<<endl<<lga+lgb<<endl<<min(xa,xb);
fout.close();
return 0;
}

10) Problema 3328 (65 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int S=6*(n-1)+6-(n-1); //capete intr-o zi dupa taiere(dimineata)
cout<<S-1; //in ziua respectiva i se mai taie un cap
return 0;
}
11) Problema 3383 (10 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

ifstream fin("cifmaxmin.in");
ofstream fout("cifmaxmin.out");
int
n,i,x,vpar[1001],vimpar[1001],k,l,nrmax,nrmin=999,nr,cminpar=999,cmaxpar,cminimpar
=999,cmaximpar;

int main()
{
fin>>n;
for(i=1;i<=n;i++)
{
fin>>x;
if(x%2==0)
vpar[++k]=x;
else vimpar[++l]=x;
}
int nrpetrica=k;
int nrionut=l;
for(k=1;k<=nrpetrica;k++)
{
int par=vpar[k];
while(par!=0)
{
cminpar=min(par%10,cminpar);
cmaxpar=max(par%10,cmaxpar);
par/=10;
}
vpar[k]=cmaxpar*10+cminpar;
}
for(l=1;l<=nrionut;l++)
{
int impar=vimpar[l];
while(impar!=0)
{
cminimpar=min(impar%10,cminimpar);
cmaximpar=max(impar%10,cmaximpar);
impar/=10;
}
vimpar[l]=cminimpar*10+cmaximpar;
}
for(k=1;k<=nrpetrica;k++)
nrmax=max(nrmax,vpar[k]);
for(l=1;l<=nrionut;l++)
nrmin=min(nrmin,vimpar[l]);
fout<<nrmax<<" "<<nrpetrica<<" "<<nrmin<<" "<<nrionut;
return 0;
}

12) Problema 3384 (50 puncte)

Cod:

#include <bits/stdc++.h>
using namespace std;

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

int oglindit(int n)
{
int x=0;
while(n!=0)
{
x=x*10+n%10;
n/=10;
}
return x;
}
int main()
{
int n,cod=0,x=0;
fin>>n;
while(n!=0)
{
cod+=n;
x=oglindit(n);
x/=10;
n=oglindit(x);
}
fout<<cod;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy