I. 1.
1. d. (20 * 23) / 2 * 2
I. 2.
c. 010111
I. 3.
c. 2
I. 4.
b. 3,0,2,1,3,2,1
I. 5.
a. 4.
II. 1.
a. 9752.
b. 321, 642
c.
#include <iostream>
using namespace std;
int x, p = 1, m = -1, c;
int main(){
cin>>x;
p = 1, m = -1;
while(p <= x){
c = (int)(x / p) % 10;
if(c > m){
m = c, p = p * 10;
}
else{
x = (int)(x / (p * 10)) * p + x % p;
}
}
if(m >= 0)
cout<<x;
else
cout<<"nul";
return 0;
}
d.
CITESTE x
p <- 1; m <- -1
REPETA
c <- [x / p] % 10
DACA c > m ATUNCI
m <- c; p <- p * 10
ALTFEL
x <- [x / (p * 10)] * p + x % p
PANA CAND p > x
DACA m >= 0 ATUNCI SCRIE x
ALTFEL SCRIE "nul"
II. 2.
mare, rau; ocean, ploaie, rau
II. 3.
struct lalea{
char denumire[20];
struct x{
int nrFire, pretFir;
}stoc;
}f[10];
III. 1.
III. 2.
int S(int x){
int s = 0;
for(int i = 1; i <= x / 2; i ++)
if(x % i == 0)
s += i;
s += x;
return s;
}
int abundent(int n){
float val = S(n)/ n;
bool g = false;
for(int k = 1; k < (n - 1); k ++){
float x = S(k) / k;
if(x >= val)
g = true;
}
if(g)
return 0;
return 1;
}
#include <iostream>
using namespace std;
int ns, np, mat[1005][55];
int main(){
cin>>ns>>np;
for(int i = 1; i <= ns; i ++)
for(int j = 1; j <= np; j ++)
cin>>mat[i][j];
for(int i = 1; i <= ns; i ++){
int maxim = mat[i][1], col = 1;
for(int j = 2; j <= np; j ++)
if(mat[i][j] > maxim)
maxim = mat[i][j], col = j;
cout<<i<<":"<<col<<" ";
}
return 0;
}
III. 3.
a.
Algoritmul proiectat foloseste 2 vectori de frecventa pentru a numara
de cate ori apare fiecare sufix si fiecare prefix in fisierul dat.
Pentru fiecare nr. x din fisier am aflat sufixul si prefixul de 2 cifre
si am incrementat frecventa corespunzator.
Complexitatea de timp a algoritmului proiectat este O(n) deoarece
am parcurs fisierul o singura data.
b.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.txt");
int fvs[105], fvp[105], suf, pre, x, p;
int main(){
while(in>>x){
if(x >= 100){
suf = x % 100;
p = 1;
int cop = x;
while(cop){
p *= 10;
cop /= 10;
}
pre = x / (p / 100);
fvs[suf]++;
fvp[pre]++;
}
}
int cnt = 0;
for(int i = 10; i <= 99; i ++)
if(fvs[i] == fvp[i] && fvs[i] > 0)
cnt++;
cout<<cnt;
return 0;
}