当前位置:网站首页>[day_050422] statistical palindrome
[day_050422] statistical palindrome
2022-07-26 06:12:00 【On the Bank of Anhe Bridge】
Statistical palindrome
Title source
Cattle from : Statistical palindrome
Title Description
“ Palindrome string ” It's a string that is read both forward and backward , such as “level” perhaps “noon” And so on are palindrome strings . Hua Hua likes this palindrome string with symmetrical beauty very much , On her birthday, she got two gifts, one was string A And string B. Now she is very curious about whether there is any way to put the string B Insert string A Make the resulting string a palindrome string . You accept Huahua's request , Help her find out how many ways to insert a new string into a palindrome string . If the string B If the insertion position is different, it will be considered as different methods .
for example :
A = “aba”,B = “b”. Here you are 4 Plant a handle B Insert A The way to :
- stay A Before the first letter of : “baba” Not a palindrome
- In the first letter ‘a’ after : “abba” It's palindrome.
- In the letters ‘b’ after : “abba” It's palindrome.
- In the second letter ’a’ after “abab” Not a palindrome
So the answer is 2
Input description
Each group has two lines of input data . The first line is string A The second behavior string B String length is less than 100 And contain only lowercase letters
Output description
Output a number , Represents a string B Insert string A Then the number of methods to form a palindrome string
Example 1
Input
aba
bOutput
2
Thought analysis
- How to judge palindrome string , Whether the inverted string is equal to the original string
- Traverse the first string , Insert the second string , Judge whether it is a palindrome string , Insert after the last position
- Define a... Every time you insert string Object to save the inserted results , Avoid modifying the original string
Code display
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
// Judging palindrome string
bool IsPalindrome(string s)
{
string temp = s;
reverse(s.begin(), s.end());
if (s == temp)
{
return true;
}
return false;
}
int main()
{
string s1, s2;
while (cin >> s1 >> s2)
{
int count = 0;
// The back of the last position should also be spliced , So the circulation condition has "="
for (int i = 0; i <= s1.size(); i++)
{
string s_temp = s1;
s_temp.insert(i, s2);
// Judge whether the spliced string is palindrome
if (IsPalindrome(s_temp))
{
count++;
}
}
cout << count;
}
return 0;
}
summary
- call reverse(str.begin( ),str.end ( ) ), To a string Object is inverted
- str1.insert(pos ,str2 ), take str2 String insertion str1 Of pos Location
- Compare whether the strings are equal reference :C/C++ Method of comparing strings in
边栏推荐
- Taobao JD pinduoduo Tiktok taote 1688 and other multi platform commodity app details API interfaces (commodity details page data interface, commodity sales interface, keyword search commodity sales in
- VS中使用动态库
- 移动web
- redis 哨兵集群搭建
- 【Oracle SQL】计算同比与环比(列转行进行偏移)
- 2022 National latest fire-fighting facility operator (Senior fire-fighting facility operator) simulation test questions and answers
- Youwei low code: Brick life cycle component life cycle
- Leetcode:741. picking cherries
- L. Link with Level Editor I dp
- 【Day03_0420】C语言选择题
猜你喜欢

Registration conditions for system integration project management engineer (intermediate level of soft exam) in the second half of 2022

Kingbasees SQL language reference manual of Jincang database (7. Conditional expression)

Distributed | practice: smoothly migrate business from MYCAT to dble

Youwei low code: Brick life cycle component life cycle

Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 4

Convolutional neural network (III) - target detection

Leetcode:934. The shortest Bridge

光量子里程碑:6分钟内解决3854个变量问题

卸载手机自带APP的操作步骤

Excitation method and excitation voltage of hand-held vibrating wire vh501tc acquisition instrument
随机推荐
Unity2d animator cannot create transition
Latex merges multiple rows and columns of a table at the same time
Recursive processing - subproblem
Intelligent fire protection application based on fire GIS system
MySQL multi table query introduction classic case
【Day_07 0425】合法括号序列判断
【Day_02 0419】倒置字符串
VS中使用动态库
【pytorch】图片增广
H. Take the Elevator 贪心
漫谈软件缺陷管理的实践
Can you make a JS to get the verification code?
Learn about spark project on nebulagraph
CV (1)- Introduction
【Day_04 0421】计算糖果
How can machinery manufacturing enterprises do well in production management with the help of ERP system?
Taobao pinduoduo Tiktok 1688 Suning taote jd.com and other keyword search commodity API interfaces (keyword search commodity API interface, keyword search commodity list interface, classification ID s
【Day_07 0425】Fibonacci数列
Is the transaction in mysql45 isolated or not?
Database SQL language practice