
目录
1. 分割回文串 🌟🌟
2. 六角填数 ※
3. 查找书籍 🌟
🌟 每日一练刷题专栏 🌟
Golang每日一练 专栏
Python每日一练 专栏
C/C++每日一练 专栏
Java每日一练 专栏
1. 分割回文串
给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 。返回 s 所有可能的分割方案。
回文串 是正着读和反着读都一样的字符串。
示例 1:
输入:s = "aab" 输出:[["a","a","b"],["aa","b"]]
示例 2:
输入:s = "a" 输出:[["a"]]
提示:
- 1 <= s.length <= 16
- s仅由小写英文字母组成
出处:
https://edu.csdn.net/practice/26880576
代码:
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    bool isPali(string s)
    {
        for (int i = 0; i < s.length() / 2; i++)
            if (s[i] != s[s.length() - i - 1])
                return false;
        return true;
    }
    void dfs(vector<vector<string>> &ans, vector<string> &tmp, int n, string s)
    {
        if (n == s.length())
        {
            ans.push_back(tmp);
            return;
        }
        for (int i = n; i < s.length(); i++)
        {
            if (isPali(s.substr(n, i - n + 1)))
            {
                tmp.push_back(s.substr(n, i - n + 1));
                dfs(ans, tmp, i + 1, s);
                tmp.pop_back();
            }
        }
    }
    vector<vector<string>> partition(string s)
    {
        vector<vector<string>> ans;
        vector<string> tmp;
        dfs(ans, tmp, 0, s);
        return ans;
    }
};
string Vector2dToString(vector<vector<string>> vec2d, string sep = ",")
{
    stringstream ss;
    ss << "[";
    for (int i = 0; i < vec2d.size(); ++i) {
        ss << "[";
        copy(vec2d[i].begin(), vec2d[i].end(), ostream_iterator<string>(ss, sep.c_str()));
		ss.seekp(-(int)sep.size(), ios_base::end);
        ss << "]" << sep;
    }
    ss.seekp(-(int)sep.size(), ios_base::end);
    ss << "]";
    return ss.str();
}
int main()
{
	Solution s;
	string str = "aab";
    cout << Vector2dToString(s.partition(str)) << endl;
    cout << Vector2dToString(s.partition("a")) << endl;
    return 0;
}输出:
[[a,a,b],[aa,b]]
 [[a]]
2. 六角填数
题目描述
 如下图所示六角形中,有12个点,依次填入1~12的数字,使得每条直线上的数字之和都相同。其中,已经替你填好了点1,2,3的数字,请你计算其他位置所代表的数字是多少?
输入
输入仅一行,以空格隔开,分别表示已经填好的点1,2,3的数字。
输出
输出仅一行,以空格隔开,分别表示所有位置所代表的数字。
样例输入:
1 8 2样例输出:
1 8 2 9 7 11 10 12 3 5 6 4以下程序实现了这一功能,请你填补空白处的内容:
```c++
 #include <iostream>
 #include <cmath>
 #include <cstdio>
 #include <cstring>
 using namespace std;
 #define eps 10e-10
 #define N 15
 int a[N];
 bool vis[N];
 void dfs(int x)
 {
     if (x == 1 || x == 2 || x == 3)
     {
         dfs(x + 1);
         return;
     }
     if (x > 12)
     {
         int t[6];
         t[0] = a[1] + a[3] + a[6] + a[8];
         t[1] = a[1] + a[4] + a[7] + a[11];
         t[2] = a[2] + a[3] + a[4] + a[5];
         t[3] = a[2] + a[6] + a[9] + a[12];
         t[4] = a[8] + a[9] + a[10] + a[11];
         t[5] = a[12] + a[10] + a[7] + a[5];
         for (int i = 1; i < 6; ++i)
         {
             if (t[i] != t[i - 1])
                 return;
         }
         for (int i = 1; i <= 12; i++)
             cout << a[i] << " ";
         return;
     }
     for (int i = 1; i < 13; ++i)
     {
         ________________;
     }
 }
 int main()
 {
     memset(vis, 0, sizeof(vis));
     cin >> a[1];
     vis[a[1]] = 1;
     cin >> a[2];
     vis[a[2]] = 1;
     cin >> a[3];
     vis[a[3]] = 1;
     dfs(1);
     return 0;
 }
 ```
出处:
https://edu.csdn.net/practice/26880577
代码:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define eps 10e-10
#define N 15
int a[N];
bool vis[N];
void dfs(int x)
{
    if (x == 1 || x == 2 || x == 3)
    {
        dfs(x + 1);
        return;
    }
    if (x > 12)
    {
        int t[6];
        t[0] = a[1] + a[3] + a[6] + a[8];
        t[1] = a[1] + a[4] + a[7] + a[11];
        t[2] = a[2] + a[3] + a[4] + a[5];
        t[3] = a[2] + a[6] + a[9] + a[12];
        t[4] = a[8] + a[9] + a[10] + a[11];
        t[5] = a[12] + a[10] + a[7] + a[5];
        for (int i = 1; i < 6; ++i)
        {
            if (t[i] != t[i - 1])
                return;
        }
        for (int i = 1; i <= 12; i++)
            cout << a[i] << " ";
        return;
    }
    for (int i = 1; i < 13; ++i)
    {
		if (!vis[i])
		{
		    vis[i] = 1;
		    a[x] = i;
		    dfs(x + 1);
		    vis[i] = 0;
		}
    }
}
int main()
{
    memset(vis, 0, sizeof(vis));
    cin >> a[1];
    vis[a[1]] = 1;
    cin >> a[2];
    vis[a[2]] = 1;
    cin >> a[3];
    vis[a[3]] = 1;
    dfs(1);
    return 0;
}输入输出:
1 8 2↙
 1 8 2 9 7 11 10 12 3 5 6 4
3. 查找书籍
给定n本书的名称和定价,本题要求编写程序,查找并输出其中定价最高和最低的书的名称和定价。 输入格式: 输入第一行给出正整数n(<10),随后给出n本书的信息。每本书在一行中给出书名,即长度不超过30的字符串,随后一行中给出正实数价格。题目保证没有同样价格的书。
输出格式:
 在一行中按照“价格, 书名”的格式先后输出价格最高和最低的书。价格保留2位小数。
输入样例:
 3
 Programming in C
 21.5
 Programming in VB
 18.5
 Programming in Delphi
 25.0
输出样例:
25.00, Programming in Delphi
 18.50, Programming in VB
出处:
https://edu.csdn.net/practice/26880578
代码:
#include<stdio.h>
struct book
{
    float price;
    char a[30];
};
int main()
{
    int n;
    scanf("%d",&n);
    char a[30];
    int i,k,maxi=0,mini=0;
    book b[10];
    for(i=0;i<n;i++)
    {
        fflush(stdin);
        for(k=0;;k++)
        {
            b[i].a[k]=getchar();
            if(b[i].a[k]=='\n')
            {
                b[i].a[k] = '\0';
                break;
            }
        }
        scanf("%f",&b[i].price);
    }
    for(i=1;i<n;i++)
    {
        if(b[i].price>b[maxi].price)
        {
            maxi=i;
        }
        if(b[i].price<b[mini].price)
        {
            mini=i;
        }
    }
    printf("%.2f,%s\n",b[maxi].price,b[maxi].a);
    printf("%.2f,%s",b[mini].price,b[mini].a);
    return 0;
}输出:
略
🌟 每日一练刷题专栏 🌟
✨ 持续,努力奋斗做强刷题搬运工!
👍 点赞,你的认可是我坚持的动力!
🌟 收藏,你的青睐是我努力的方向!
✎ 评论,你的意见是我进步的财富!
☸ 主页:https://hannyang.blog.csdn.net/
|  | Golang每日一练 专栏 | 
|  | Python每日一练 专栏 | 
|  | C/C++每日一练 专栏 | 
|  | Java每日一练 专栏 | 






![[python][vpython]用vpython实现小球砸弹簧代码](https://img-blog.csdnimg.cn/f339354c25964d1c990b16054819ee2d.jpeg)












