Salut. Ma poate ajuta cineva cu aceste 2 probleme de informatica clasa a 12-a? Sunt din teste de antrenament bac 2007 profil real varianta 16 (c++ va rog).
Răspunsuri la întrebare
1)
#include <iostream>
using namespace std;
int permutare(int k, int n) {
int inv1=0, inv2=0, cn, cif=0, i, nr=0;
cn = n;
while (n) {
cif++;
n /= 10;
}
n = cn;
for (i=1; i<=cif-k; i++) {
inv1 = inv1*10 + n%10;
n /= 10;
}
for (i=1; i<=k; i++) {
inv2 = inv2*10 + n%10;
n /= 10;
}
for (i=1; i<=cif-k; i++) {
nr = nr*10 + inv1%10;
inv1 /= 10;
}
for (i=1; i<=k; i++) {
nr = nr*10 + inv2%10;
inv2 /= 10;
}
return nr;
}
int main()
{
int k, n;
cin >> k >> n;
cout << permutare(k, n);
return 0;
}
2)
#include <iostream>
using namespace std;
string combine(string a, string b) {
int i, j;
string c;
c = a + b;
for (i=0; i<c.length()-1; i++) {
for (j=i+1; j<c.length(); j++) {
if (c[i] > c[j]) swap(c[i], c[j]);
}
}
return c;
}
int main()
{
int i;
string a, b;
cin >> a >> b;
cout << combine(a, b);
return 0;
}
using namespace std;
int main() {
int i, j;
string a, b, c;
cin >> a >> b;
c = a + b;
for (i=0; i for (j=i+1; j if (c[i] > c[j]) swap(c[i], c[j]);
}
}
cout << c;
return 0;
}