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 IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】