2078 Problem H Secret Message

题目描述

Jack and Jill developed a special encryption method, so they can enjoy conversations without worrrying about eavesdroppers. Here is how: let L be the length of the original message, and M be the smallest square number greater than or equal to L. Add (M − L) asterisks to the message, giving a padded message with length M. Use the padded message to ?ll a table of size K × K, where K2= M. Fill the table in row-major order (top to bottom row, left to right column in each row). Rotate the table 90 degrees clockwise. The encrypted message comes from reading the message in row-major order from the rotated table, omitting any asterisks.

For example, given the
original message ‘iloveyouJack’, the message length is L = 12. Thus the padded
message is ‘iloveyouJack****’, with length M = 16. Below are the two tables
before and after rotation.

Then we read the secret message as
‘Jeiaylcookuv’.

输入

The ?rst line of input is the
number of original messages, 1 ≤ N ≤ 100. The following N lines each have a
message to encrypt. Each message contains only characters a–z (lower and upper
case), and has length 1 ≤ L ≤ 10 000.

输出

For each original message,
output the secret message.

样例输入

2
iloveyoutooJill
TheContestisOver

样例输出

iteiloylloooJuv
OsoTvtnheiterseC
解题心得:  题意是输入字符串(长度L),然后将每个字符从上到下,从左到右挨着放到一个k*k的方格里,剩余的用*补上,然后将方格顺时针旋转一下(90度),然后在按照从上到下,从左到右的顺序输出(*省略掉)。K值:先把L开方,然后向上取整再加1,然后平方,即得到K的值。  我在做的时候忘记了把X清零,结果又是浪费了时间。。。

代码:
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <cmath>
 5
 6 using namespace std;
 7
 8 int main()
 9 {
10     int n;
11     int x=0;
12     int size=0;
13     double k=0;
14     int k1=0;
15     int s;
16     char a[10000];
17     char c[100][100];
18     scanf("%d",&n);
19     for(int i=0;i<n;i++){
20         cin>>a;
21         size=strlen(a);
22         k=sqrt(size);
23         k1=ceil(k);
24         s=k1*k1;
25         if(size!=s){
26             int add=s-size;
27             for(int i1=0;i1<add;i1++){
28                 a[size+i1]=‘*‘;
29             }
30             a[size+add]=‘\n‘;
31         }
32          for(int j=0;j<k1;j++){
33                 for(int j1=0;j1<k1;j1++){
34                     c[j][j1]=a[x++];
35                 }
36             }
37             x=0; //做的时候被我落掉了,结果好久才找到错误!
38             for(int r=0;r<k1;r++){
39                 for(int p=k1-1;p>=0;p--){
40                     if(c[p][r]!=‘*‘){
41                         printf("%c",c[p][r]);
42                     }
43                 }
44             }
45             printf("\n");
46
47     }
48     return 0;
49 }
时间: 2024-10-25 07:16:28

2078 Problem H Secret Message的相关文章

bzoj 1590: [Usaco2008 Dec]Secret Message 秘密信息

1590: [Usaco2008 Dec]Secret Message 秘密信息 Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共有M(1≤M≤50000)条.反间谍能力很强的约翰已经部分拦截了这些信息,知道了第i条二进制信息的前bi(l<bi≤10000)位.他同时知道,奶牛使用N(1≤N≤50000)条密码.但是,他仅仅了解第J条密码的前cj(1≤cj≤10000)位. 对于每条密码J,他想知道有多少截得的信息能够和它匹配.也就是说,有多

P2922 [USACO08DEC]秘密消息Secret Message

P2922 [USACO08DEC]秘密消息Secret Message 题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret binary messages to each other. Ever the clever counterspy, Farmer John has intercepted the first b_i (1 <= b_i <= 1

Problem H. The Fence

/** 题目:Problem H. The Fence 链接:https://vjudge.net/problem/Gym-101090H 题意:给定一个字符串,只有0或者1: 问:假如两个不同的1之间的0,1数量是k的倍数(包括0倍)则输出这两个1的位置: 思路:%k:直到遇到两个相同的余数,说明之间的01数量为k的倍数. */ #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1

Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description In a Famous TV Show “Find Out” there are n characters and only one Horrible Truth. To make the series breathtaking all way long, the sc

Moscow Subregional 2010 Problem H. Hometask 转化、素数筛选

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem H. Hometask Time limit: 1 second Memory limit: 256 megabytes Kolya is still trying to pass a test on Numbers Theory. The lecturer is so desperate about Kolya's knowl

Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di

1590: [Usaco2008 Dec]Secret Message 秘密信息

1590: [Usaco2008 Dec]Secret Message 秘密信息 Time Limit: 5 Sec  Memory Limit: 32 MBSubmit: 209  Solved: 143[Submit][Status][Discuss] Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共有M(1≤M≤50000)条.反间谍能力很强的约翰已经部分拦截了这些信息,知道了第i条二进制信息的前bi(l<bi≤10000)位.他同时知

ZCMU Problem H: Crixalis&#39;s Equipment(贪心,排序)

#include<stdio.h> #include<stdlib.h> struct node { int a,b; }c[1002]; int cmpxy(const struct node *c,const struct node *d) { return (d->b - d->a) - (c->b - c->a); } int main() { int n,i,v,t,flag; // freopen("a.txt","

实验12:Problem H: 整型数组运算符重载

Home Web Board ProblemSet Standing Status Statistics Problem H: 整型数组运算符重载 Problem H: 整型数组运算符重载 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 643  Solved: 401[Submit][Status][Web Board] Description 定义Array类: 1.拥有数据成员int length和int *mems,分别是数组中元素的个数和元