Salut,am nevoie de rezolvarile la problemele 2420,1903,2253,621,1400,995,999,2347 rezolvarea in C++ si va rog sa fie la nivel de clasa a 9 a,am nevoie urgent azi
Răspunsuri la întrebare
Nu ai mentionat de unde dar presupun ca sunt de pe pbinfo. O zi frumoasa!
Problema 2420:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int sum=0;
for(int i = 2 ; i < n ; ++i)
{
sum+=n/i;
}
if(n==1)
cout << n;
else
cout << sum+n+1;
return 0;
}
Problema 1903:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
ifstream fin("vterminal.in");
ofstream fout("vterminal.out");
int prim(int n)
{
if(n==0 || n==1) return 0;
if(n==2) return 1;
if(n%2==0) return 0;
else
for(int d=3;d*d<=n;d+=2)
{
if(n%d==0) return 0;
}
return 1;
}
int main()
{
int n,x,s=0;
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x;
if(prim(x)) s=s+x;
}
fout<<s%9;
return 0;
}
Problema 2253:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
ifstream fin("vacantadevara.in");
ofstream fout("vacantadevara.out");
int main()
{
int n;
fin >> n;
int ok=0 , a[1000];
int cif=0;
for(int i = 0 ; i < n ; ++i)
fin >> a[i];
sort(a,a+n);
for(int i = 0 ; i < n ; ++i)
{
if(a[i]!=0)
{
cif=a[i];
break;
}
}
fout << cif;
for(int i = 0 ; i < n ; ++i)
{
if(a[i]==cif && ok==0)
{
ok++;
}
else
fout << a[i];
}
return 0;
}
Problema 621:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
int n , a[10001] , max = 0 , f[10001]={0} , cnt = 0;
cin >> n;
for(int i = 0 ;i < n ; ++i)
{
cin >> a[i];
if(a[i]>max) max = a[i];
f[a[i]]++;
}
sort(a , a+n);
for(int i = 1 ; i <= max ; ++i)
{
cnt++;
if(f[i]==0)
{
cout << i;
break;
}
}
if(cnt==max)cout << a[n-1]+1;
return 0;
}
Problema 1400:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int a[1000] , f[10000]={0};
for(int i = 0 ; i < n ; ++i)
{
cin >> a[i];
f[a[i]]++;
}
int cnt=0;
for(int i = 0 ; i <= 10000 ; ++i)
{
if(f[i]!=0)
{
if(f[i]%2!=0)
cnt++;
}
}
if(cnt==0 || cnt==1)
cout << "DA";
else
cout << "NU";
}
Problema 995:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream fin("numere6.in");
ofstream fout("numere6.out");
int main()
{
int n , m;
fin >> n >> m;
int v[20];
int p = 0;
if(n==0)
v[p]=0 , p++;
if(m==0)
v[p]=0 , p++;
while(n)
{
v[p]=n%10;
p++;
n/=10;
}
while(m)
{
v[p]=m%10;
p++;
m/=10;
}
for(int i = 9 ; i >= 0 ; --i)
{
for(int j = 0 ; j < p ; ++j)
{
if(i==v[j])
fout << i;
}
}
return 0;
}
Problema 999:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream cin("numere7.in");
ofstream cout("numere7.out");
int main()
{
int n , m;
cin >> n >> m;
int v[30];
int cnt=0;
int p = 0;
if(n==0)
cnt++;
if(m==0)
cnt++;
while(n)
{
if(n%10==0)
cnt++;
else
v[p]=n%10 , p++;
n/=10;
}
while(m)
{
if(m%10==0)
cnt++;
else
v[p]=m%10 , p++;
m/=10;
}
if(p==0)
cout << 0;
sort(v , v+p);
for(int i = 0 ; i < p ; ++i)
{
cout << v[i];
if(i==0)
{
for(int j = 0 ; j < cnt ; ++j)
cout << 0;
}
}
return 0;
}
Problema 2347:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
ifstream cin("furnici.in");
ofstream cout("furnici.out");
int a[101001];
int nrdiv(int n)
{
int d = 2 , prod = 1;
while(n > 1)
{
int p = 0;
while(n % d == 0) p++,n /= d;
if(p) prod *= (p+1);
d++;
if(d*d > n) d = n;
}
return prod;
}
int main()
{
int n , x , l = 0 , lmax = 0;
cin >> n;
for(int i = 1 ; i <= n ; ++i)
{
cin >> x;
a[i] = nrdiv(x);
}
for(int i = 1 ; i <= n ;++i)
{
if(a[i] < a[i-1]) l++;
else if(a[i] >= a[i-1])
{
if(l) lmax++;
l = 0;
}
}
if(l) cout << lmax+1;
else cout << lmax;
}