#Description
原题
#Algorithm
以159263748为例
0 0+4 0+2*4
1 1+4
2 2+4
3 3+4
这样很容易就找的模拟的办法了
一个一个填过去就好了
关键是这题卡C++ 连getline都会TLE
只能用gets和字符数组
不能用字符串类
#Code
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX_L = 1e5 + 9;
char s[MAX_L];
char ans[MAX_L];
void solve()
{
gets(s);
int l = strlen(s);
int x;
scanf("%d\n", &x);
memset(ans, 0, sizeof(ans));
int t = l / x;
if (l % x != 0) t++;
int a = 0;
int b = 0;
for (int i = 0; i < l; i++) {
ans[a + b * x] = s[i];
b++;
if (a + (b - 1) * x == l - 1) {
t--;
a++;
b = 0;
continue;
}
if (b == t) {
a++;
b = 0;
}
}
printf("%s\n", ans);
}
int main()
{
// freopen("input.txt", "r", stdin);
int t;
scanf("%d\n", &t);
for (int i = 1; i <= t; i++) {
printf("Case #%d:\n", i);
solve();
}
}
本文探讨了一个特殊的字符串转换问题,使用C++语言解决。通过避免使用getline和字符串类,采用gets和字符数组,成功克服了时间限制问题。文章提供了完整的代码示例,展示了如何将输入字符串按特定规则进行转换。
113

被折叠的 条评论
为什么被折叠?



