TOJ 1547

简介: 1547.   To and FroTime Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 885   Accepted Runs: 692 Mo and Larry have devised a way of encrypting messages.
1547.   To and Fro
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 885    Accepted Runs: 692



Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. For example, if the message is "There's no place like home on a snowy night" and there are five columns, Mo would write down

t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x

Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character 'x' to pad the message out to make a rectangle, although he could have used any letter.

Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as

toioynnkpheleaigshareconhtomesnlewx

Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.

Input

There will be multiple input sets. Input for each set will consist of two lines. The first line will contain an integer in the range 2 ... 20 indicating the number of columns used. The next line is a string of up to 200 lower case letters. The last input set is followed by a line containing a single 0, indicating end of input.

Output

Each input set should generate one line of output, giving the original plaintext message, with no spaces.

Sample Input

5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0

Sample Output

theresnoplacelikehomeonasnowynightx
thisistheeasyoneab
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int i,j,k,T;
    char s[205];
    while(cin>>T,T)
    {
        memset(s,0,sizeof(s));
        cin>>s;
        int len = strlen(s);
        //二维字符数组申请 
        int row = len/T;
        int col = T;
        char **str = new  char *[row];//  new  (char *)[row]会在编译器里CE 
        for(i=0;i<row;i++)
            str[i] = new char[col];
        k = 0;
        for(i=0;i<row;i++)
        if((i&1)==0)//行号为0,2,4,加上括号,否则,恰好相反,汗 
        {
            for(j=0;j<col;j++)
                str[i][j] = s[k++]; 
        }
        else
        {
            for(j=col-1;j>=0;j--)
                str[i][j] = s[k++];
        }
        /*
        for(i=0;i<row;i++)
        {
            for(j=0;j<col;j++)
                cout<<str[i][j];
            cout<<endl;
        }
        */
        //按要求输出
        for(i=0;i<col;i++)
            for(j=0;j<row;j++)
                cout<<str[j][i];//注意不是str[i][j] 
        cout<<endl;
        //释放 
        for(i=0;i<row;i++)
            delete []str[i];
        delete []str;
    }
    //system("pause");
    return 0;
}
         
        
        

 

目录
相关文章
|
9天前
|
人工智能 JavaScript Linux
【Claude Code 全攻略】终端AI编程助手从入门到进阶(2026最新版)
Claude Code是Anthropic推出的终端原生AI编程助手,支持40+语言、200k超长上下文,无需切换IDE即可实现代码生成、调试、项目导航与自动化任务。本文详解其安装配置、四大核心功能及进阶技巧,助你全面提升开发效率,搭配GitHub Copilot使用更佳。
|
3天前
|
JSON API 数据格式
OpenCode入门使用教程
本教程介绍如何通过安装OpenCode并配置Canopy Wave API来使用开源模型。首先全局安装OpenCode,然后设置API密钥并创建配置文件,最后在控制台中连接模型并开始交互。
1524 5
|
11天前
|
存储 人工智能 自然语言处理
OpenSpec技术规范+实例应用
OpenSpec 是面向 AI 智能体的轻量级规范驱动开发框架,通过“提案-审查-实施-归档”工作流,解决 AI 编程中的需求偏移与不可预测性问题。它以机器可读的规范为“单一真相源”,将模糊提示转化为可落地的工程实践,助力开发者高效构建稳定、可审计的生产级系统,实现从“凭感觉聊天”到“按规范开发”的跃迁。
1668 17
|
9天前
|
人工智能 JavaScript 前端开发
【2026最新最全】一篇文章带你学会Cursor编程工具
本文介绍了Cursor的下载安装、账号注册、汉化设置、核心模式(Agent、Plan、Debug、Ask)及高阶功能,如@引用、@Doc文档库、@Browser自动化和Rules规则配置,助力开发者高效使用AI编程工具。
1271 6
|
10天前
|
消息中间件 人工智能 Kubernetes
阿里云云原生应用平台岗位急招,加入我们,打造 AI 最强基础设施
云原生应用平台作为中国最大云计算公司的基石,现全面转向 AI,打造 AI 时代最强基础设施。寻找热爱技术、具备工程极致追求的架构师、极客与算法专家,共同重构计算、定义未来。杭州、北京、深圳、上海热招中,让我们一起在云端,重构 AI 的未来。
|
13天前
|
IDE 开发工具 C语言
【2026最新】VS2026下载安装使用保姆级教程(附安装包+图文步骤)
Visual Studio 2026是微软推出的最新Windows专属IDE,启动更快、内存占用更低,支持C++、Python等开发。推荐免费的Community版,安装简便,适合初学者与个人开发者使用。
1292 12
|
7天前
|
云安全 安全
免费+限量+领云小宝周边!「阿里云2026云上安全健康体检」火热进行中!
诚邀您进行年度自检,发现潜在风险,守护云上业务连续稳健运行
1180 2
|
13天前
|
人工智能 测试技术 开发者
AI Coding后端开发实战:解锁AI辅助编程新范式
本文系统阐述了AI时代开发者如何高效协作AI Coding工具,强调破除认知误区、构建个人上下文管理体系,并精准判断AI输出质量。通过实战流程与案例,助力开发者实现从编码到架构思维的跃迁,成为人机协同的“超级开发者”。
1015 94
|
9天前
|
人工智能 JSON 自然语言处理
【2026最新最全】一篇文章带你学会Qoder编辑器
Qoder是一款面向程序员的AI编程助手,集智能补全、对话式编程、项目级理解、任务模式与规则驱动于一体,支持模型分级选择与CLI命令行操作,可自动生成文档、优化提示词,提升开发效率。
787 8
【2026最新最全】一篇文章带你学会Qoder编辑器

热门文章

最新文章