I. 1.
d. 75
I. 2.
b. 0, 2, 0, 1
I. 3.
c. (80, 70, 30, 20)
I. 4.
c. 5
I. 5.
a. 4
II. 1.
a. 11100
b. 24680, 86420
c.
#include <iostream>
using namespace std;
int a, c, b, x;
int main(){
cin>>a;
c = 0;
do{
b = a, x = 0;
do{
if(b % 10 == c){
x = 1;
}
b /= 10;
}while(b != 0 && x != 1);
cout<<x<<" ";
c = c + 2;
}while(c <= 9);
return 0;
}
d.
CITESTE a
c <- 0
REPETA
b <- a; x <- 0
CAT TIMP b != 0 SI x != 1 EXECUTA
DACA b % 10 = c ATUNCI
x <- 1
b <- [b / 10]
SCRIE x, ' '
c <- c + 2
PANA CAND c > 9
II. 2.
struct calculator{
char monitor;
struct mem{
int interna, externa;
} memorie;
}c;
II. 3.
for(i = 0; i < 9; i ++)
for(j = 0; j < 9; j++)
if(i + j >= 9 && i > j)
a[i][j] = '<';
else
a[i][j] = '>';
III. 1.
int suma(int a, int b){
int sum = 0;
for(int i = 1; i <= min(a, b); i++)
if(a % i == 0 && b % i == 0)
sum += i;
return sum;
}
III. 2.
#include <iostream>
#include <cstring>
using namespace std;
char s[105], sol[105] = "";
bool g = false;
int main(){
cin.getline(s, 100);
char *p = strtok(s, " ");
while(p != NULL){
if(strlen(p) < 3){
strcat(sol, p);
strcat(sol, " ");
}
else{
char rot[105]; g = true;
rot[strlen(p) - 1] = p[0];
for(int i = 0; i < (strlen(p) - 1); i++)
rot[i] = p[i + 1];
rot[strlen(p)] = '\0';
strcat(sol, rot);
strcat(sol, " ");
}
p = strtok(NULL, " ");
}
if(g){
cout<<sol;
}
else{
cout<<"nu exista";
}
return 0;
}
III. 3.
a.
Algoritmul proiectat retine nr. de aparitii al fiecarui element din fisier
in vectorul fv.
In cazul in care avem nr. par de elemente in fisier si nu exista
elemente care apar de nr. impar de ori sau avem
nr. impar de elemente si exista un singur nr. care apare de nr. impar de ori
in fisier, atunci putem forma un sir palindromic.
b.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.in");
int fv[1005], x, cnt = 0;
bool ok = false;
int main(){
while(in>>x){
fv[x]++;
cnt++;
}
int p = 0, imp = 0;
for(int i = 1; i <= 1000; i ++){
if(fv[i] % 2 == 0 && fv[i] > 0){
p++;
}
else
if(fv[i] % 2 == 1 && fv[i] > 0){
imp++;
}
}
cout<<p<<" "<<imp<<"\n";
if(cnt % 2 == 0 && imp == 0)
ok = true;
else
if(cnt % 2 == 1 && imp == 1)
ok = true;
if(ok){
cout<<"DA";
}
else{
cout<<"NU";
}
return 0;
}