0828-T2 超级幸运数
0828-T2 超级幸运数
题意
给出数字
思路
分
当
如
求出
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll to_int(string s) {
ll res = 0;
for (auto c : s) res = res * 10 + c - '0';
return res;
}
ll solve(int A, int B) {
string a = to_string(A);
string b = to_string(B);
int len = min(a.size(), b.size());
for (int i = len - 1; i >= 0; i --) {
if (a.substr(a.size() - i - 1, i + 1) == b.substr(0, i + 1)) {
string c = a;
if (i + 1 < b.size())
c = c + b.substr(i + 1);
return to_int(c);
}
}
string c = a + b;
return to_int(c);
}
int main() {
ll A, B;
cin >> A >> B;
ll ans1 = solve(A, B);
ll ans2 = solve(B, A);
cout << min(ans1, ans2);
return 0;
}
本文来自博客园,作者:maniubi,转载请注明原文链接:https://www.cnblogs.com/maniubi/p/18386457,orz
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
· DeepSeek本地性能调优
· 一文掌握DeepSeek本地部署+Page Assist浏览器插件+C#接口调用+局域网访问!全攻略