I. 1.
c. 10
I. 2.
d. valoare = 2 * x.cantitate * x.pret
I. 3.
a. {volei, handbal}
I. 4.
b. 3
I. 5.
c. x = 3, y = 8
II. 1.
a. 4
b. 11, 13
c.
#include <iostream>
using namespace std;
int n, i, k;
int main(){
cin>>n;
i = 2, k = 0;
while(n >= i){
while(n % i == 0){
k++;
n = n / i;
}
if(i == 2)i++;
else{
i += 2;
}
}
cout<<k;
return 0;
}
II. 2.
2022, 2023
II. 3.
char *p = strtok(s, " ");
p = strtok(NULL, " ");
strcpy(id, p);
strcat(id, "2022");
III. 1.
void secventa(int & n){
int v[15], sz = 0;
while(n){
v[sz++] = n % 10;
n = n / 10;
}
for(int i = 1; i < sz; i ++)
if(v[i - 1] == v[i] && v[i] == 2)
v[i - 1] = 0;
for(int i = sz - 1; i >= 0; i --)
n = n * 10 + v[i];
}
III. 2.
#include <iostream>
using namespace std;
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
int a[105][105], n, m, sol;
int main(){
cin>>m>>n;
for(int i = 1; i <= m; i ++)
for(int j = 1; j <= n; j ++)
cin>>a[i][j];
for(int i = 1; i <= m; i ++)
for(int j = 1; j <= n; j ++){
int minim = 11;
for(int k = 0; k < 4; k ++){
int iv = i + di[k], jv = j + dj[k];
if(iv >= 1 && iv <= m && jv >= 1 && jv <= n)
if(minim > a[iv][jv])
minim = a[iv][jv];
}
if(minim > a[i][j])
sol += (minim - a[i][j]);
}
cout<<sol;
return 0;
}
III. 3.
a.
Algoritmul proiectat parcurge fisierul dat si memoreaza fiecare nr. in a
si in pre numarul precedent lui a.
Daca a este diferit de precedent si a se afla in intervalul [x, y], atunci
incrementez numarul de elemente distincte care apartin [x, y] reprezentat
de variabila cnt.
Complexitatea de timp : O(n).
Complexitatea de memorie : O(1)
b.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.txt");
int x, y, pre = -1, cnt, a;
int main(){
in>>x>>y;
while(in>>a){
if(pre != -1 && pre != a && a >= x && a <= y)
cnt++;
pre = a;
}
cout<<cnt;
return 0;
}