A1118 | [COCI-2007_2008-contest3]#6 TAJNA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Every evening, little Ivica sends secret messages to little Marica through e-mail. Knowing Ivica's e-letter travels unguarded through the network on its way to Marica's e-mailbox, they have decided to encrypt every message using the following algorithm:
• Suppose Ivica's message consists of N characters.
• Ivica must first find a matrix consisting of R rows and C columns such that R ≤ C and R·C = N. If there is more than one such matrix, Ivica chooses the one with the most rows.
• Ivica writes his message into the matrix in row-major order. In other words, he writes the first segment of the message into the first row, the second segment into the second row and so on.
• The message he sends to Marica is the matrix read in column-major order.
Marica has grown tired of spending her precious time deciphering Ivica's messages, so you must write a program to do it for her.
• Suppose Ivica's message consists of N characters.
• Ivica must first find a matrix consisting of R rows and C columns such that R ≤ C and R·C = N. If there is more than one such matrix, Ivica chooses the one with the most rows.
• Ivica writes his message into the matrix in row-major order. In other words, he writes the first segment of the message into the first row, the second segment into the second row and so on.
• The message he sends to Marica is the matrix read in column-major order.
Marica has grown tired of spending her precious time deciphering Ivica's messages, so you must write a program to do it for her.
输入格式
The input contains the received message, a string of lowercase letters of the English alphabet (with no spaces).
The number of letters will be between 1 and 10
0.
The number of letters will be between 1 and 10
0.
输出格式
Output the original (decrypted) message.
输入输出样例
输入 #1
bok
输出 #1
bok
输入 #2
koaski
输出 #2
kakosi
输入 #3
boudonuimilcbsai
输出 #3
bombonisuuladic
Ivica wants to send the message "bombonisuuladici" containing 16 letters. He can use a 1×16, 2×8 or
4×4 matrix. Of these, the 4×4 has the most rows. When the message is written into it, the matrix looks
like this:
b o m b
o n i s
u u l a
d i c i
4×4 matrix. Of these, the 4×4 has the most rows. When the message is written into it, the matrix looks
like this:
b o m b
o n i s
u u l a
d i c i
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted