zoukankan      html  css  js  c++  java
  • 第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;
        }
    }
  • 相关阅读:
    CSS中position小解
    position
    mac默认安装postgresql, 如何让postgresql可以远程访问
    The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0.
    active admin gem error
    psql 无法添加超级用户
    ubuntu 15.04 安装Balsamiq Mockups 3
    Rails html 写public里图片的路径
    rails c 历史命令
    undefined local variable or method `per' for []:ActiveRecord::Relation
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433211.html
Copyright © 2011-2022 走看看