I. 1.
a. x = 4 si y = 2
I. 2.
b. 5
I. 3.
b. strchr("aeiou", x);
I. 4.
b. 5413
I. 5.
c. 16
II. 1.
a. 3
b. 25, 30
c.
#include <iostream>
using namespace std;
int m, n, p, q, s1, s2, s;
int main(){
cin>>m>>n>>p>>q;
while(p <= q){
if(p % m == 0 || p % n == 0)
s1++;
if(p % m == 0 && p % n == 0)
s2++;
p++;
}
s = s1 - 2 * s2;
cout<<s;
return 0;
}
d.
CITESTE m, n, p, q
s1 <- 0, s2 <- 0
PENTRU i <- p, q, 1 EXECUTA
DACA i % m = 0 SAU i % n = 0 ATUNCI
s1 <- s1 + 1
DACA i % m = 0 SI i % n = 0 ATUNCI
s2 <- s2 + 1
p <- p + 1
s <- s1 - 2 * s2
SCRIE s
II. 2.
3 -> 5 -> 1 -> 2 -> 6
II. 3.
fig.raza = 1;
fig.centru.x = 0;
fig.centru.y = 0;
III. 1.
void Impare(int & n){
int v[15], it = 0;
while(n){
int cif = n % 10;
if(cif % 2 == 1)
v[it++] = (cif - 1);
else
v[it++] = cif;
n /= 10;
}
for(int i = (it - 1); i >= 0; i --)
n = n * 10 + v[i];
}
III. 2.
#include <iostream>
using namespace std;
int m, n, a[25][25];
bool g = false;
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 && g == false; i++)
for(int j = 1; j <= (n / 2); j++)
if(a[i][j] != a[i][n - j + 1])
g = true;
if(g)
cout<<"NU";
else
cout<<"DA";
return 0;
}
III. 3.
a.
Algoritmul proiectat parcurge fisierul dat prin intermediul variabilei x
iar in variabila maxim este retinuta valoarea maxima curenta
Daca am gasit un nou maxim sau daca maximul este egal cu x si pre
este egal cu maximul atunci afisez x
Complexitate de timp: O(n)
Complexitate de memorie : O(1)
b.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.txt");
int x, pre = -1, maxim = -1;
int main(){
while(in>>x){
if(maxim < x){
maxim = x;
cout<<x<<" ";
}
else
if(maxim == x && pre == x)
cout<<x<<" ";
pre = x;
}
return 0;
}