Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

S1

1. a)
2. a) 621131
b) 0
c) citeşte n
n1<-0
n2<-0
k1<-0
p<-1
cât timp n ≠ 0 execută
│ dacă (n%10)%2=0 atunci
│ │ n2<-n2 * 10 + n%10
│ │ altfel
│ │ n1<-n1 * 10 + n%10
│ │ p<-p*10
│ └■
│ n<-[n/10]
└■
x<-n2*p + n1
scrie x
d) #include <iostream>

using namespace std;

int main() {
int n=0, n1=0, n2=0, k1=0, p=1, x;
cin>>n;
while (n!=0) {
if ((n%10)%2==0)
n2=n2*10+n%10;
else {
n1=n1*10+n%10;
k1++;
}
n/=10;
}
for (int i=1; i<=k1; i++)
p*=10;
x=n2*p+n1;
cout<<x;
return 0;
}

S2
1. b)
2. (1, 3) si (3, 4)
25550
3. 1: 3
2: 1,3
3: 4,5
4: 5
5: 2
4. #include <iostream>
#include <cstring>

using namespace std;

int main() {
char s[21]="", s2[21]="";
cin.getline(s, 21);
int i=0, k=1;
while (s[i]!=' ') {
s2[i]=s[i];
i++;
k++;
}
s2[i]=' ';
while (s[i]==' ')
i++;
while (i<strlen(s)) {
s2[k]=s[i];
k++;
i++;
}
cout<<s2;
return 0;
}

SAU

#include <iostream>
#include <cstring>

using namespace std;

int main() {
char s[21], t[21];
cin.get(s, 21);
char *p=strchr(s, ' ');
while (p[1]==' ')
strcpy(p, p+1);
t[strlen(p+1)]=' ';
strcat(t, s);
cout<<t;
return 0;
}
5. -

S3
1. c)
2. a) f(5)=68;
b) 8
3. int f(int n, int v[]) {
int ord=0;
for (int i=2; i<=n; i++) {
if (v[i-1]<v[i]) {
if (ord==0)
ord=1;
else
if (ord==2)
ord=-1;
}
else
if (v[i-1]>v[i]) {
if (ord==0)
ord=2;
else
if (ord==1)
ord=-1;
}
}
return ord;
}
4. a)

You might also like