Home
О нас
Products
Services
Регистрация
Войти
Поиск
Lena1867
@Lena1867
July 2022
1
17
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 Ответы
dve mashiny odnovremenno vyshli iz punktov a i b pri etom do punkta s pervaya mashidde1288c028a4717f11acaaaa7b3f257 23551
Answer
Lena1867
August 2022 | 0 Ответы
v treugolnike dve storony ravny 12sm i 8sm a ugol mezhdu nimi 60 najdite plo
Answer
Lena1867
August 2022 | 0 Ответы
dopolnite tekst neobhodimymi slovami
Answer
Lena1867
July 2022 | 0 Ответы
tex]...
Answer
Lena1867
July 2022 | 0 Ответы
ch i k otpravleniyu avtobusa uspeli rasstoyanie ot derevni do stancii ravno 6 km
Answer
Lena1867
July 2022 | 0 Ответы
tex]...
Answer
Lena1867
July 2022 | 0 Ответы
soznymi slovami nuzhno sostavit predlozhenie
Answer
Lena1867
July 2022 | 0 Ответы
dopolnite predlozheniya pridatochnymi i opredelite ih vid 1v gorodeshiroko raz
Answer
Lena1867
July 2022 | 0 Ответы
vstavte propushennye slova084724d026dd686f2cb044fc5c7486b1 82957
Answer
Lena1867
July 2022 | 0 Ответы
ispravit oshibki dopushennye v upotreblenii chislitelnyh
Answer
рекомендуемые вопросы
rarrrrrrrr
August 2022 | 0 Ответы
o chem dolzhny pozabotitsya v pervuyu ochered vzroslye pri organizacionnom vyvoze n
danilarsentev
August 2022 | 0 Ответы
est dva stanka na kotoryh vypuskayut odinakovye zapchasti odin proizvodit a zapcha
myachina8
August 2022 | 0 Ответы
najti po grafiku otnoshenie v3v1 v otvetah napisano 9 no nuzhno reshenie
ydpmn7cn6w
August 2022 | 0 Ответы
Choose the correct preposition: 1.I am fond (out,of,from) literature. 2.where ar...
millermilena658
August 2022 | 0 Ответы
opredelite kak sozdavalas i kto sozdaval arabskoe gosudarstvo v kracii
MrZooM222
August 2022 | 0 Ответы
ch ajtmanov v rasskaze krasnoe yabloko ispolzuet metod rasskaz v rasskaze opi
timobila47
August 2022 | 0 Ответы
kakovo bylo naznachenie kazhdoj iz chastej vizantijskogo hrama pomogite pozhalujsta
ivanyyaremkiv
August 2022 | 0 Ответы
moment. 6....
pozhalujsta8b98a56c0152a07b8f4cbcd89aa2f01e 97513
sarvinozwakirjanova
August 2022 | 0 Ответы
pomogite pozhalusto pzha519d7eb8246a08ab0df06cc59e9dedb 6631
×
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 © 2024 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; }