I. 1.
B. (x > 100) && ( (x * x * x) % 1000 == 0 )
I. 2.
b)
u = 128
c)
subprogram FRec(u)
DACA u = 1 ATUNCI
RETURNEAZA 0
DACA u % 2 = 0 ATUNCI
RETURNEAZA 1 + FRec(u / 2)
DACA u % 2 = 1 ATUNCI
RETURNCEAZA 1 + FRec(u * 3 + 1)
d)
#include <iostream>
using namespace std;
int F(int u){
int count = 0;
while(u != 1){
if(u % 2 == 0)
u = u / 2;
else
u = u * 3 + 1;
count = count + 1;
}
return count;
}
II. 1.
A. 777
II. 2.
C. 4
II. 3.
a)
S = {"abc", "cde", "afe"}
b)
#include <iostream>
#include <cstring>
using namespace std;
int n, m, ln = -1;
char D[105][105], A[105];
bool ok = true;
int main(){
cin>>m;
for(int i = 0; i < m; i++)
A[i] = (char)((int)('a') + i);
cin>>n;
for(int i = 1; i <= n; i++){
cin>>D[i];
if(ln == -1)
ln = strlen(D[i]);
else
if(ln != strlen(D[i]))
ok = false;
}
if(ok){
for(int i = 1; i <= n && ok; i++)
for(int j = 1; j <= n && ok; j++)
if(i != j){
int cnt = 0;
for(int x = 0; x < strlen(D[i]); x++)
for(int y = 0; y < strlen(D[j]); y++)
if(D[i][x] == D[j][y])
cnt++;
if(cnt != 1)
ok = false;
}
}
if(ok)
cout<<"DA";
else
cout<<"NU";
}
II. 4.
a)
a0 = (40, 30, 20, 10)
a1 = (40, 10, 20, 30)
a2 = (10, 40, 20, 30)
a3 = (10, 40, 20, 30)
a4 = (10, 20, 40, 30)
b)
R = ((1, 2), (1, 3), (1, 4), (2,3), (2,4))
c)
int comp(int n, int m, int R[105][3], int a[105]){
int Ra[105];
for(int i = 1; i <= n; i++)
Ra[i] = a[i];
for(int i = 1; i <= m; i++)
if(Ra[R[i][0]] > Ra[R[i][1]]){
int aux = Ra[R[i][0]];
Ra[R[i][0]] = Ra[R[i][1]];
Ra[R[i][1]] = aux;
}
for(int i = 2; i <= n; i++)
if(Ra[i] < Ra[i - 1])
return 0;
return 1;
}
III. 1.
A. 79
III. 2.
F(0, 63, 64) = 8
III. 3.
a)
(2, 3), (1, 2)
b)
void check(int A[105][105], int n, int m, int i, int j){
A[i][j] = 1 - A[i][j];
A[i - 1][j] = 1 - A[i - 1][j];
A[i][j - 1] = 1 - A[i][j - 1];
A[i - 1][j - 1] = 1 - A[i - 1][j - 1];
}
c)
int find(int A[105][105], int n, int m){
for(int i = n - 1; i >= 0; i--)
for(int j = m - 1; j >= 0; j--)
if(A[i][j] == 1)
check(A, n, m, i, j);
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(A[i][j] == 1)
return 0;
return 1;
}