Probinfo
Probinfo
Probinfo
I.
1. d
2.
a. 2
b. 20, 28, 44, 52
c. *
d. *
II.
1. d
2. a
3.
if(d.nr % d.mic == 1){
cout << "prim";
}else{
if(d.mic * d.mic == d.nr) cout << "patrat";else cout <<
d.mic << " " << d.nr / d.mic;
}
4.
for(i = 1; i <= 9; i++){
for(j = 1; j <= 9; j++){
if(i == 1) a[1][j] = 1;
if(j == 1) a[i][1] = 1;
if(i != 1 && j!= 1) a[i][j] = a[i-1][j-1] + 1;
}
}
5.
#include <cstring>
#include <iostream>
using namespace std;
int main(){
char s[101],maxim = '0',cuv[101];
cin.get(s,101);
int nr = 0;
char *p = strtok(s," ");
while(p){
if(p[0] > maxim && p[0] >= '0' && p[0] <= '9'){
strcpy(cuv,p);
nr++;
}
p = strtok(0," ");
}
if(nr == 0) cout << "nu exista"; else cout << cuv;
}
III.
1. d
2. (fondante,acadele)
3.
int echilibrat(int n){
int nr = 0,sump = 0, sumi = 0;
while(n){
if(nr % 2 == 0){
sump = sump + n % 10;
}else{
sumi = sumi + n % 10;
}
nr++; n/=10;
}
if(sump % 2 == 0 && sumi % 2 == 1)
return 1;
return 0;
}
4.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream in("bac.txt");
int x,y,p[11] = {0},c[11] = {0};
while(in >> x){
y++;
if(p[x] == 0){p[x] = y; c[x] = 1;}
else{
c[x] = y - p[x] + 1;
}
}
int maxim = 0;
for(int i = 0; i < 10; i++){
if(c[i] > maxim){
maxim = c[i];
}
}
cout << maxim<<endl;
for(int i = 0; i < 10; i++){
if(c[i] == maxim) cout << i << " ";
}
in.close();
}
*/
/*
I.
1. c
2.
a. 69
b. 86,860, 806, 68
c. *
d. *
II.
1. d
2. a
3. 1,6,8,9
4.
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
if(i == 0) a[i][j] = j;
if(j == 0) a[i][j] = j;
if(i == 9) a[i][j] = j;
if(j == 9) a[i][j] = j;
if(i && j && i != 9 && j != 9) a[i][j] = a[i][j-1] +
1;
}
}
5.
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char cod[101],cuv[101],s1[101],s2[101],s[101];
int k = 0, l = 0,p = 0;
cin.get(cuv,101);
cin.get();
cin.get(cod,101);
if(strlen(cuv)!= strlen(cod)) cout << "nu exista";
for(int i = 0; i < strlen(cod); i++){
if(cod[i] == '0' || cod[i] == '2' || cod[i] == '4' ||
cod[i] == '6' || cod[i] == '8'){
s1[++k] = cuv[i];
}else{
s2[++l] = cuv[i];
}
}
for(int i = k; i >= 1; i--){
s[++p] = s1[i];
}
for(int i = 1; i <= l; i++){
s[++p] = s2[i];
}
for(int i = 1; i <= p; i++) cout << s[i];
}
III.
1. a
2. 6, 7, 8
3.
int resturi(int n, int x,int y,int r){
int nr = 0;
for(int i = 1; i <= n; i++){
if(i % x == r && i % y == r){
nr++;
}
}
return nr;
}
4.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
// var 2
int x,y,z,k = 1,maxim = 0;
ifstream in("bac.txt");
in >> x;
while(in >> y){
if(x != y) k++;
else{
if(maxim < k) maxim = k, k = 1;
}
x = y;
}
if(x != y){
k++;
if(maxim < k) maxim = k;
}
cout << maxim;
in.close();
}
*/
/*
I.
1. b
2.
a. 55533
b. 722,7221,7122,7212
c. *
d. *
II.
1. a
2. b
3.
if(x){
cout << rezultat.cat = 2018 / x << " ";
cout << rezultat.rest = 2018 % x;
}else{
cout << "impartire nepermisa";
}
4.
4,6,8
5.
#include <iostream>
using namespace std;
int main(){
int n,v[10001] = {0},p = 0,a[101][101];
cin >> n;
for(int i = 0; i < n; i++){
cin >> v[i];
}
for(int j = 0; j < n; j++){
if(j % 2 == 0){
int p = n;
for(int i = 0; i < n;i++){
p--;
a[i][j] = v[p];
}
}else{
int p = 0;
for(int i = 0;i < n; i++){
a[i][j] = v[p];p++;
}
}
}
for(int i = 0; i < n; i++,cout << endl){
for(int j = 0; j < n; j++){
cout << a[i][j] << " ";
}
}
}
III.
1. c
2. {toc, creion, pensulă, pană, stilou}, {toc, pensula, creion, stilou,
pana}
3.
int interval(int n){
int x = n, ok = 0;
while(ok == 0){
x++;
int k = 0;
for(int i = 1; i <= x; i++){
if(x % i == 0){
k++;
}
}
if(k == 2){
ok = 1;
}
};
return x + 1;
}
4.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
// var 1
ofstream out("bac.txt");
int x,y;
cin >> x >> y;
int dif = y - x;
while(y > 0){
out << y << " ";
y = y - dif;
dif = dif - 2;
}
out << y;
out.close();
}
*/
/*
I.
1. a
2.
a. 135*234*
b. 6
c. *
d. *
II.
1. d
2. b
3.
struct meteo{
inbt luna,an;
float temperatura[13];
}m;
4.
for(i = 0; i < 9; i++){
for(j = 0; j < 9; j++){
if(i + j != 8){
a[i][j] = 1;
}else{
a[i][j] = 8, a[i][j-1] = 8, a[i][j+1] = 8;
}
}
}
III.
1. a
2. {rosu,portocaliu,albastru,roz}, {rosu,portacliu,albastru,verde}
3.
void radical(int n, int&x, int& y){
int f = 2, p;x = 1, y = 1;
while(n > 1){
p = 0;
while(n % f == 0){
p++;
n /= f;
}
if(p){
if(p % 2 == 0){
for(int i = 1; i <= p / 2; i++){
x = x * f;
}
}else{
y = y * f;
p--;
for(int i = 1; i <= p / 2; i++){
x = x * f;
}
}
}
f++;
}
}
4.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.txt");
int main(){
int x,y,okx = 1,oky = 1;
in >> x >> y;
if(x > y){
swap(x,y);
}
int z;
while(in >> z){
if(z > x && okx){
if(z > y && oky){
cout << x << y << z;
okx = 0; oky = 0;
}else{
cout << x << z;
okx = 0;
}
}else{
if(z > y && okx == 0 && oky){
cout << y << z;
oky = 0;
}else{
cout << z;
}
}
}
if(oky) cout << y;
in.close();
}
*/