专栏文章
题解:CF2168A2 Encode and Decode (Hard Version)
CF2168A2题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @min8mkvc
- 此快照首次捕获于
- 2025/12/01 22:21 3 个月前
- 此快照最后确认于
- 2025/12/01 22:21 3 个月前
注意到 最多为 , 的长度却可以到 。
所以我们用 个字母表示一个数即可,甚至只需要用到 a 与 k 之间的字母都能完成。
代码:
CPP#include <bits/stdc++.h>
#define int long long
using namespace std;
string get(int x)
{
stack <int> st;
for (int i = 0; i < 10; i ++)
{
st.push(x % 10);
x /= 10;
}
string s;
while (!st.empty())
{
s.push_back(st.top() + 'a');
st.pop();
}
return s;
}
void sol1()
{
int n;
cin >> n;
string s;
for (int i = 1; i <= n; i ++)
{
int x;
cin >> x;
s += get(x);
}
cout << s << endl;
}
void sol2()
{
string s;
cin >> s;
cout << s.size() / 10 << endl;
for (int i = 0; i < s.size(); i += 10)
{
int ret = 0;
for (int j = 0; j < 10; j ++)
ret = ret * 10 + s[i + j] - 'a';
cout << ret << " ";
}
cout << endl;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
string s;
cin >> s;
if (s == "first")
sol1();
else
sol2();
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...