第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛 K 密码 【模拟】

链接:https://www.nowcoder.com/acm/contest/90/K
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
ZiZi登录各种账号的时候,总是会忘记密码,所以他把密码都记录在一个记事本上。其中第一个密码就是牛客网的密码。

牛客网专注于程序员的学习、成长及职位发展,连接C端程序员及B端招聘方,通过IT笔试面试题库、在线社区、在线课程等提高候选人的求职效率,通过在线笔试、面试及其他工具提升企业的招聘效率。

团队由来自Google、百度、阿里、网易等知名互联网巨头的热血技术青年组成,用户覆盖全国2000多所高校的100W求职程序员及全部一线互联网企业,并仍在高速增长中。
谨慎的ZiZi当然不会直接把密码记录在上面,而是把上面的字符串经过转化后才是真正的密码。转化的规则是把字符串以n行锯齿形写出来,然后再按从左到右,从上到下读取,

即为真正的密码。如ABABCADCE以3行写出:

所以真正的密码是ACEBBACAD。但是每一次都要写出来就太麻烦了,您如果能帮他写出一个转换程序,他就送你一个气球。
输入描述:

第一行一个整数T,表示数据组数
对于每组数据,首先一个正整数n(n<=100,000),然后下一行为一个字符串,字符串长度len<=100,000。

输出描述:

对于每组数据,输出一个字符串,代表真正的密码。

示例1
输入

1
3
ABABCADCE

输出

ACEBBACAD

思路
可以模拟一下 这个过程 然后输出 用二维数组保存 或者字符串

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>

#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;

const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6;

const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        string s;
        string ans[maxn];
        cin >> n >> s;
        int len = s.size();
        for (int i = 0, j = 0; i < len; j++)
        {
            if (j % n == 0)
            {
                for (int k = 0; k < n && i < len; k++)
                    ans[k] += s[i++];
            }
            else if (j % n != n - 1)
                ans[n - 1 - j % n] += s[i++];
        }
        for (int i = 0; i < n; i++)
            cout << ans[i];
        cout << endl;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值