您的位置:首页 > 其它

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

2018-03-25 09:49 330 查看
链接: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.1415926535897
bb43
9323846264338327;
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐