Найти все симметричные натуральные числа (палиндромы) из промежутка от А до В (А и В вводятся с клавиатуры) Решать через массив.
// #includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // }}} // #defines {{{#define exp 1e-10#define sc scanf#define pr printf#define mk make_pair#define pb push_back#define pf push_front#define ll long long#define fi first#define se second#define eps 0.000000001#define INF 1000000007#define file "management"#define eps 0.000000001#define cmd 1000000009#define PI 3.14159265#define MOD 1000000007#define sz(x) ((int)(x).size())#define in(s) freopen(s, "r", stdin);#define pi 3.1415926535897#define rep(i, n) for(__typeof(n) i = 0; i < (n); i++)#define out(s) freopen(s, "w", stdout);#define sync ios_base::sync_with_stdio( 0 )// }}} using namespace std; typedef long long lglg;const int inf = 1<<30, maxN = 1000;</span>int ax[] = {0, 1, -1, 0, 0};int ay[] = {0, 0, 0, -1, 1}; int main(){ string a; int n, dp[102][102], i, j, px[102][102], py[102][102]; cin >> a; memset(dp, 0, sizeof(dp)); memset(px, -1, sizeof(px)); a = "." + a; n = a.size() - 1; for (i = 1; i <= n; i++)</span> dp[i][i] = 1; for (i = n; i >= 1; i--) for (j = i + 1; j <= n; j++)</span> { if (a[i] == a[j] && dp[i][j] < 2 + dp[i + 1][j - 1])</span> { dp[i][j] = 2 + dp[i + 1][j - 1]; px[i][j] = i + 1; py[i][j] = j - 1; } if (dp[i][j] < dp[i + 1][j])</span> { dp[i][j] = dp[i + 1][j]; px[i][j] = i + 1; py[i][j] = j; } if (dp[i][j] < dp[i][j - 1])</span> { dp[i][j] = dp[i][j - 1]; px[i][j] = i; py[i][j] = j - 1; } } cout << dp[1][n] <<<span>'\n'; int x = 1, y = n, q, w; vector ans; char z = 0; while (px[x][y] != -1) { if (px[x][y] == x + 1 && py[x][y] == y - 1) ans.push_back(a[x]); q = px[x][y]; w = py[x][y]; x = q; y = w; } if (x == y) z = a[x]; for (i = 0; i< ans.size(); i++)</span> cout << ans[i];</span> if (z != 0) cout<< z;</span> for (i = ans.size() - 1; i >= 0; i--) cout<< ans[i];</span> return 0; }