I. 1.
c. (x / y) * y == x && y >= 2
I. 2.
a. 69
b. 68, 96, 608
c.
CITESTE n
DACA n < 0 ATUNCI
n <- -n
s <- 0
REPETA
x <- n % 10
s <- x * (x + 1) / 2
n <- [n / 10]
PANA CAND n = 0
SCRIE s
d.
#include <iostream>
#include <fstream>
using namespace std;
int n, x, s;
int main(){
cin>>n;
if(n < 0)
n *= -1;
s = 0;
do{
x = n % 10;
for(int i = 1; i <= x; i ++)
s = s + x;
n = n / 10;
}while(n != 0);
cout<<s;
return 0;
}
II. 1. b. m[0].substanta.cod
II. 2. a. 3
II. 3. 1, 9, 8
II. 4.
II. 5.
for(int i = 0; i < 9; i++)
for(int j = 0; j < 9; j ++)
if(i == j || (i + j) == 8)
a[i][j] = 0;
else
if((i + j) < 8)
a[i][j] = (i + j);
else
if((i + j) > 8)
a[i][j] = i + j - 9;
III. 1.
#include <iostream>
#include <cstring>
using namespace std;
char s[105], c[105], sol[105] = "";
int main(){
cin>>s;
cin>>c;
if(strlen(s) != strlen(c)){
cout<<"cod incorect";
}
else{
char s1[105] = "", s2[105] = "";
for(int i = 0; i < strlen(s); i++){
int k = (int)(c[i]);
if(k % 2 == 1){
s1[strlen(s1)] = s[i];
s1[strlen(s1) + 1] = '\0';
}
}
for(int i = (strlen(s) - 1); i >= 0; i --){
int k = (int)(c[i]);
if(k % 2 == 0){
s2[strlen(s2)] = s[i];
s2[strlen(s2) + 1] = '\0';
}
}
strcat(sol, s2);
strcat(sol, s1);
cout<<sol;
}
return 0;
}
a. ( JAVA, C# )
III. 2.
5, 6, 7
III. 3.
int resturi(int n, int x, int y, int r){
int cnt = 0;
for(int i = 1; i <= n; i ++)
if(i % x == r && i % y == r)
cnt ++;
return cnt;
}
III. 4. a.
In algoritmul proiectat variabilele x, y si z memoreaza ultimele numere citite
Variabila secv memoreaza lungimea secventei neuniforme curente
Daca x, y si z sunt distincte atunci incrementam secv.
Daca doar y si z sunt diferite atunci secv devine 2
Daca doar z este diferit atunci secv devine 1
Complexitate de timp : O(n)
Complexitate de memorie : O(1)
b.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.txt");
int x = -1, y = -1, z, secv = 0, secvmax = -1;
int main(){
while(in>>z){
if(x != -1 && y != -1){
if(x != z && y != z && x != y)
secv++;
else
if(y != z)
secv = 2;
else{
secv = 1;
}
}
x = y, y = z;
if(secvmax < secv)
secvmax = secv;
}
cout<<secvmax;
}