sa se insireze inaintea fiecarui element palindromic maximul sirului. in c++, la nivel de clasa a 9 a, folosind vectorii
Răspunsuri la întrebare
#include <iostream>
using namespace std;
int n, i, v[100], maxim, pal, num, j;
int main()
{
cout << "n= "; cin >> n;
cout << "introdu " << n << " numere naturale: " << endl;
cin >> v[0];
maxim=v[0];
for (i=1; i<n; ++i)
{
cin >> v[i];
if (v[i]>maxim) maxim=v[i];
}
for (i=0; i<n; ++i)
{
pal=0;
num=v[i];
while (num>0)
{
pal=pal*10+num%10;
num=num/10;
}
if (v[i]==pal)
{
for (j=n; j>i; --j)
{
v[j]=v[j-1];
}
++n;
v[i]=maxim;
++i;
}
}
cout << "Tabloul dupa inserari: " << endl;
for (i=0; i<n; ++i)
{
cout << v[i] << " ";
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define n 5
int a[n] = {321,22,3113,441,4114};
int i,j,k,r,p,l,max;
int b[100];
palindrom( j ){
k = 1;
r = 0;
p = 0;
while(k != 0 && j != 0){
k = j % 10;
j = j / 10;
b[r] = k;
r++;
}
for(i=0; i<r; i++){
if(b[i] != b[r-1-i]){
break;
}else{
p+=1;
}
}
if(p == r){
printf("%d|%d ",max,a[l]);
}
}
int main(){
printf("a[] = ");
for(l=0; l<n; l++){
printf("%d ",a[l]);
}
max = a[0];
for(l=0; l<n; l++){
if(max<a[l]){
max = a[l];
}
}
printf("\n\nElementul maxim:\nmax = %d",max);
printf("\n\n");
for(l=0; l<n; l++){
palindrom(a[l]);
}
printf("\n\n");
return 0;
}
Coroana?