You are on page 1of 13

/*

#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream in("bac.txt");
int n, x, minp = (1 << 30), mini = (1 << 30), maxi = 0, maxp = 0, ok = 0,
u;
in >> n;
for (int i = 1; i <= 2 * n; i++) {
in >> x;
u = i;
if (i <= n) {
i = x;
if (maxi < i && i % 2 == 1) maxi = i;
if (maxp < i && i % 2 == 0) maxp = i;
}
else {
i = x;
if (i < minp && i % 2 == 0) minp = i;
if (i < mini && i % 2 == 1) mini = i;
}
if (maxi < minp && maxp < mini) {
ok = 1;
}
i = u;
}
if (ok == 1) cout << "DA"; else cout << "NU";
in.close();
}
*/
/*
* Varianta 5
*
I.
1. b. 5
2. b. f(19);
3. d. (oud, violete, geranium)
4. a. 17
5. c. 5
II.
1.
a. 4
b. (10, 20, 30,0),(10, 40, 50,0),(10, 50, 80,0),(90, 20, 10,0)
c.
#include <iostream>
using namespace std;
int main(){
int x,z = 1,y;
cin >> n;
do{
cin >> y;
for(int d = 2; d <= y; d++){
if(x % d == 0 && y % d == 0 && d > z) z =
d;
}
x = y;
}while(y);
cout << z;
}
d.
citește x
(număr natural nenul)
z<-1
┌repetă
│ citeşte y (număr natural) d <- 2
│┌cat timp d <= y executa
││┌dacă x%d=0 și y%d=0 și d>z atunci
│││ z<-d
││└■
|| d <- d + 1;
│└■
│ x<-y
└până când y=0
scrie z
2.
struct{
char marca[30];
struct{
int turatie; float capacitate;
}motor;
}m;
3.
succes5
III.
1.
int Suma(int n){
int sum = 0,x = n;
while(x){
if(x % 10 == (x / 10) % 10){
sum = sum + x % 100;
}
x = x / 10;
}
return sum;
}
2.
#include <iostream>
using namespace std;
int main() {
int a[101][101], n,nr = 0;
cin >> n;
for(int i = 0; i <= n + 1; i++){
a[0][i] = 100;
a[n + 1][i] = 100;
a[i][0] = 100;
a[i][n + 1] = 100;
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if (a[i][j] == 3) {
if (a[i - 1][j] == 0 || a[i + 1][j] == 0
|| a[i][j + 1] == 0 || a[i][j - 1] == 0)
{
cout << i << " ";
nr++;
}
}
}
}
if (nr == 0) cout << "nu exista";
}
3.
#include <iostream>
#include <fstream>
using namespace std;
int x, fv[12],c = 0,ap[12];
int main() {
ifstream in("bac.txt");
while(in >> x)
{
c++;
while(x)
{
if (ap[x % 10] == 0) {
fv[x % 10]++;
ap[x % 10]++;
}
x /= 10;
}
for(int j = 0; j < 10; j++)
ap[j] = 0;
}
int max = -1;
for(int i = 0; i < 10; i++)
{
if(fv[i] == c)
{
if(max < i)
{
max = i;
}
}
}
cout << max;
in.close();
}
*/
/*
Varianta 4
I.
1. a. x=4 şi y=2
2. b. 5
3. b. strchr("aeiou",x)
4. b. 5413
5. c. 16
II.
1.
a. 3
b. 26,27
c.
#include <iostream>
using namespace std;
int main(){
int n,m,p,q;
int s1 = 0, s2 = 0;
cin >> n >> m >> p >> q;
while(p <= q){
if(p % m == 0 || p % n == 0) s1 = s1 + 1;
if(p % m == 0 && p % n == 0) s2 = s2 + 1;
p++;
}
int s = s1 - 2 * s2;
cout << s;
}
d.
citeşte m,n,p,q (numere naturale nenule,p≤q)
s1<-0; s2<-0
┌pentru p = p,q,+1 executa
│┌dacă p%m=0 sau p%n=0 atunci
││ s1<-s1+1
│└■
│┌dacă p%m=0 şi p%n=0 atunci
││ s2<-s2+1
│└■
└■ s<-s1-2*s2 scrie s
2.
3 - 5 - 1 - 2 - 6
3.
fig.centru.x = 0;
fig.centru.y = 0;
fig.raza = 1;
III.
1.
void Impare(int& n)
{
int x = 0,v[20],t = 0;
while(n)
{
if((n % 10) % 2 == 1)
v[++t] = ((n % 10) - 1);
else
v[++t] = (n % 10);

n /= 10;
}
n = 0;
while(t)
{
n = n * 10 + v[t] % 10;
t--;
}
}
2.
#include <iostream>
using namespace std;
int main()
{
int a[51][51], n, m;
cin >> m >> n;
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> a[i][j];
}
}
int k = 1, l = n, ok = true;
while(k < n / 2 + 1 && l > n / 2 + 1)
{
for (int i = 1; i <= m; i++)
if (a[i][k] != a[i][l]) ok = false, cout <<
a[i][l] << " ";
k++;
l--;
}
if (ok == false) cout << "NU"; else cout << "DA";
}
3.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("bac.txt");
int maxim = 0, x, ok = 1;
while(in >> x)
{
if(x > maxim)
{
ok = 1;
maxim = x;
cout << maxim << " ";
}else
{
if(x < maxim)
{
ok = 0;
}
if(ok == 1 && x == maxim)
{
cout << maxim << " ";
}
}
}
in.close();
}
*/
/*
* Varianta 2
I.
1. b. ’m’==’M’
2. c. 75 45 15 15
3. a. (ciocolată, caramel, frișcă)
4. d. 5
5. b. 2,2,3,4,0,3
II.
1.
a. 1227
b. 11,101,1001
c.
#include <iostream>
using namespace std;
int main(){
int n,m = 0,x = 1;
while(x <= 9){
int cp = n;
while(cp){
if(cp % 10 == x){
m = m * 10 + x;
}
cp = cp / 10;
}
x++;
}
cout << m;
}
d.
citeşte n
(număr natural)
m<-0; x<-1
┌pentru x <- 1,9,+1 execută
│ cp<-n
│┌cât timp cp≠0 execută
││┌dacă cp%10=x atunci
│││ m<-m*10+x
││└■
││ cp<-[cp/10]
│└■
│ x<-x+1
└■
scrie m
2.
for(int i = strlen(b) - 1; i >= 0 && strlen(a) <= 3; i--){
strcat(a,b + i);
}
if(strlen(a) == 3) cout << a; else cout << "nedeterminat";
3.
p.x == c.centru.x && p.y == c.centru.y
III.
1.
int MaxImp(int a, int b)
{
for(int i = b; i >= a; i--){
int x = i, k = 1;
for(int j = 1; j <= x; j++){
if(x % j == 0 && j % 2 == 1){
k = k * j;
}
}
if(k > i){
return i;
}
}
return 0;
}
2.
#include <iostream>
using namespace std;
int main()
{
int a[21][21], n;
cin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> a[i][j];
}
}
int coordx,coordy;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if(a[1][1] == a[i][j])
{
coordy = j;
}else
{
j = n + 1;
}
}
if (a[i][1] == a[1][1] && i <= coordy)
{
coordx = i;
}
else i = n + 1;
}
cout << coordx;

}
3.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("bac.txt");
int x, fv[1001] = {0}, maxim = 0, minim = (1 << 30);
while(in >> x)
{
fv[x]++;
if (maxim < x) maxim = x;
if (minim > x) minim = x;
}
for(int i = minim; i <= maxim; i++)
{
if(fv[i] > 0 && i % 2 == 1)
{
for(int k = 1; k <= fv[i]; k++)
{
cout << i << " ";
}
}
}
for (int i = minim; i <= maxim; i++)
{
if (fv[i] > 0 && i % 2 == 0)
{
for (int k = 1; k <= fv[i]; k++)
{
cout << i << " ";
}
}
}
in.close();
}
*/
/*
* Varianta 1
I.
1. c. !(!(x<3)||!(y>=5))
2. b. m,n,d-1
3. a. (afine, caise, mere)
4. b. 1,2,3,4
5. b. 0,0,0,0,2,3
II.
1.
a. 4
b. 45,46,47
c.
#include <iostream>
using namespace std;
int main(){
int n,k,x;
cin >> n >> k;
int p = 0, i = 1;
while(i <= n){
x = i;
while(x % k == 0){x = x / k; p++;}
i++;
}
cout << p;
}
d.
citeşte n,k
(numere naturale, k număr prim)
p<-0;
┌cât timp i<-1,n,+1 execută
│ x<-i
│┌cât timp x%k=0 execută
││ x[x/k]; p<-p+1
│└■
└■
scrie p
2.
if(d.luna == e.dev.luna){if(d.zi < e.dev.zi) cout << 1;}else{
if(d.luna < e.dev.luna) cout << 1;
}
3.
for(int i = 1; i <= 5; i++){
for(int j = 1; j <= 5; j++){
if(i == 1)
a[1][j] = 4;
if(j == 1)
a[i][1] = 4;
if(i >= j && j >= 2){
a[i][j] = a[i][j - 1] - 1;
}else{
if(j > i){
a[i][j] = a[i][j - 1];
}
}
}
}

III.
1.
int Egal(int n)
{
int cnt = 0,cifra = 0, nr = 0;
int x = n;
while(x)
{
int cif = x % 10;
if(cif % 2 == 1)
{
cifra = cif;
break;
}
x /= 10;
}
while(n)
{
if((n % 10) % 2 == 1 )
{
nr++;
if((n % 10) == cifra)
{
cnt++;
}
}
n /= 10;
}
if (cnt == nr) return 1; return 0;
}
2.
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[101];
int n, ok = 0;
cin.get(s, 101);
cin.get();
cin >> n;
char* p = strtok(s, " ");
while(p)
{
if (strlen(p) == n) cout << p << endl, ok = 1;
p = strtok(0, " ");
}
if(ok == 0) cout << "nu exista";
}
3.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("bac.txt");
int n, x, y, z,nr = 3,c = 0;
cin >> n >> x >> y >> z;
while(nr < n)
{
c = z + y - x;
x = y;
y = z;
z = c;
nr++;
}
nr = 3;
out << z << " " << y << " " << x << " ";
while(nr < n)
{
c = y + x - z;
out << c << " ";
z = y;
y = x;
x = c;
nr++;
}
out.close();
}
*/
/*
* Model
I.
1. d. !(n%20!=0 || n%19==0)
2. a. f(1000,2);
3. b. (agar, paciuli, tuberoze)
4. c. 6
5. d. 11
II.
1.
a. 1 2 2 3 3 3 4
b. 45 , 55
c.
#include <iostream>
using namespace std;
int main(){
int n,k = 1;
cin >> n;
while(n >= 1){
if(n > k) i = k;
else i = n;
n-=i;
while(i >= 1){
cout << k << " "; i--;
}
k++;
}
}
d.
citeşte n
(număr natural)
k<-1
┌execută
│┌dacă n>k atunci i<-k
││altfel i<-n
│└■
│ n<-n-i
│┌cât timp i>=1 execută
││ scrie k,' '; i<-i-1
│└■
│ k<-k+1
└cat timp n > 1
2.
struct complex{
float pim; int pre;
}z[20];
3.
for(int i = 1; i <= 5; i++){
for(int j = 1; j <= 5; j++){
if(i == 1){
a[1][j] = j;
}else{
if(i >= 2){
a[i][j] = a[i-1][j] + 5;
}
}
}
}
III.
1.
int CifrePrime(int n)
{
int suma = 0;
while(n){
int cif = n % 10;
if(cif == 2 || cif == 3 || cif == 5 || cif == 7)
{
suma = suma + cif;
}
n = n / 10;
}
return suma;
}
2.
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char s[101],*q,*p,t[101] = "",
int u = 0,ok = 0;
cin.get(s,101);
p = strtok(s," ");
while(p){
for(int i = 0; i < strlen(p); i++){
if(strchr("aeiou",p[i]) == 0){
t[u++] = p[i];
ok = 1;
break;
}
}
if(ok == 0){
cout << "nu exista";
break;
}
p = strtok(0," ");
break;
}
if(ok == 1){
int ok2 = 0,nr = 0;
q = strtok(s," ");
while(q){
nr++;
if(nr == 2){
for(int i = 0; i < strlen(p); i++){
if(strchr("aeiou",p[i])){
t[u++] = p[i];
ok2 = 1;
break;
}
}
if(ok2 == 0){
cout << "nu exista";
}
}
q = strtok(0," ");
break;
}
}
t[++u] = s[strlen(s) -1];
for(int i = 0; i < u; i++){
cout << t[i];
}
}
3.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream in("bac.txt");
int x,fv[101] = {0},maxim = 0,minim = (1 << 30);
while(in >> x){
fv[x]++;
if(maxim < x) maxim = x;
if(minim > x) minim = x;
}
int maxk = 0,suma = 0;
for(int i = minim; i <= maxim; i++){
if(fv[i]){
suma = suma + fv[i];
if(suma > maxk){
maxk = suma;
}
} else suma = 0;
}
cout << maxk;
in.close();
}
*/

You might also like