Home
О нас
Products
Services
Регистрация
Войти
Поиск
Lena1867
@Lena1867
July 2022
1
28
Report
Найти все симметричные натуральные числа (палиндромы) из промежутка от А до В (А и В вводятся с клавиатуры) Решать через массив.
Please enter comments
Please enter your name.
Please enter the correct email address.
Agree to
terms of service
You must agree before submitting.
Send
Answers & Comments
morgan2014
// #includes {{{
#include <stdio.h>#include <iostream>#include <cmath>#include <algorithm>#include <fstream>#include <vector>#include <complex>#include <queue>#include <set>#include <map>#include <cstdlib>#include <cstdio>#include <cstring>#include <cassert>#include <ctime>#include <cmath>#include <string>#include <deque>#include <list>#include <math.h>#include <fstream>#include <stack>#include <iomanip>#include <bitset>#include <memory.h>#include <bitset>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <ctime>#include <assert.h>#include <stdarg.h>#include <time.h>#include <limits.h>#include <ctype.h>#include <complex>#include <bits/stdc++.h>// }}} // #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;
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++)
dp[i][i] = 1;
for (i = n; i >= 1; i--)
for (j = i + 1; j <= n; j++)
{
if (a[i] == a[j] && dp[i][j] < 2 + dp[i + 1][j - 1])
{
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])
{
dp[i][j] = dp[i + 1][j];
px[i][j] = i + 1;
py[i][j] = j;
}
if (dp[i][j] < dp[i][j - 1])
{
dp[i][j] = dp[i][j - 1];
px[i][j] = i;
py[i][j] = j - 1;
}
}
cout << dp[1][n] <<
'\n'
;
int x = 1, y = n, q, w;
vector<char> 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++)
cout << ans[i];
if (z != 0)
cout<< z;
for (i = ans.size() - 1; i >= 0; i--)
cout<< ans[i];
return 0;
}
0 votes
Thanks 0
More Questions From This User
See All
Lena1867
August 2022 | 0 Ответы
Две машины одновременно вышли из пунктов А и Б, при этом до пункта С первая маши...
Answer
Lena1867
August 2022 | 0 Ответы
В треугольнике две стороны равны 12см и 8см, а угол между ними 60° . Найдите пло...
Answer
Lena1867
August 2022 | 0 Ответы
Дополните текст необходимыми словами...
Answer
Lena1867
July 2022 | 0 Ответы
tex]...
Answer
Lena1867
July 2022 | 0 Ответы
ч, и к отправлению автобуса успели? Расстояние от деревни до станции равно 6 км...
Answer
Lena1867
July 2022 | 0 Ответы
tex]...
Answer
Lena1867
July 2022 | 0 Ответы
созными словами нужно составить предложение...
Answer
Lena1867
July 2022 | 0 Ответы
Дополните предложения придаточными и определите их вид. 1)В городе... широко раз...
Answer
Lena1867
July 2022 | 0 Ответы
Вставьте пропущенные слова...
Answer
Lena1867
July 2022 | 0 Ответы
Исправить ошибки, допущенные в употреблении числительных...
Answer
рекомендуемые вопросы
rarrrrrrrr
August 2022 | 0 Ответы
о чем должны позаботиться в первую очередь взрослые при организационном вывозе н...
danilarsentev
August 2022 | 0 Ответы
Есть два станка на которых выпускают одинаковые запчасти один производит a запча...
myachina8
August 2022 | 0 Ответы
Найти по графику отношение V3:V1. В ответах написано 9, но нужно решение...
ydpmn7cn6w
August 2022 | 0 Ответы
Choose the correct preposition: 1.I am fond (out,of,from) literature. 2.where ar...
millermilena658
August 2022 | 0 Ответы
Определите Как создавалась и кто создавал арабское государство в крации...
MrZooM222
August 2022 | 0 Ответы
Ч. Айтманов в рассказе "Красное яблоко" использует метод рассказ в рассказе. Опи...
timobila47
August 2022 | 0 Ответы
каково было назначение каждой из частей византийского храма? помогите пожалуйста...
ivanyyaremkiv
August 2022 | 0 Ответы
moment. 6....
Участник Знаний
August 2022 | 0 Ответы
Пожалуйста!!!!!!!!!!!!...
sarvinozwakirjanova
August 2022 | 0 Ответы
помогите пожалусто пж...
×
Report "Найти все симметричные натуральные числа (палиндромы) из промежутка от А до В (А..."
Your name
Email
Reason
-Select Reason-
Pornographic
Defamatory
Illegal/Unlawful
Spam
Other Terms Of Service Violation
File a copyright complaint
Description
Helpful Links
О нас
Политика конфиденциальности
Правила и условия
Copyright
Контакты
Helpful Social
Get monthly updates
Submit
Copyright © 2025 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <stdio.h>#include <iostream>#include <cmath>#include <algorithm>#include <fstream>#include <vector>#include <complex>#include <queue>#include <set>#include <map>#include <cstdlib>#include <cstdio>#include <cstring>#include <cassert>#include <ctime>#include <cmath>#include <string>#include <deque>#include <list>#include <math.h>#include <fstream>#include <stack>#include <iomanip>#include <bitset>#include <memory.h>#include <bitset>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <ctime>#include <assert.h>#include <stdarg.h>#include <time.h>#include <limits.h>#include <ctype.h>#include <complex>#include <bits/stdc++.h>// }}} // #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;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++) dp[i][i] = 1; for (i = n; i >= 1; i--) for (j = i + 1; j <= n; j++) { if (a[i] == a[j] && dp[i][j] < 2 + dp[i + 1][j - 1]) { 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]) { dp[i][j] = dp[i + 1][j]; px[i][j] = i + 1; py[i][j] = j; } if (dp[i][j] < dp[i][j - 1]) { dp[i][j] = dp[i][j - 1]; px[i][j] = i; py[i][j] = j - 1; } } cout << dp[1][n] <<'\n'; int x = 1, y = n, q, w; vector<char> 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++) cout << ans[i]; if (z != 0) cout<< z; for (i = ans.size() - 1; i >= 0; i--) cout<< ans[i]; return 0; }