English 中文(简体)
改用齐格扎格印刷有什么更好的解决办法?
原标题:What is a better solution for a changed zigzag printing?

2. 考虑以下变化: 作为一种投入,一些行文和插手,写在一行背后和整个行各处。 例如,提供的投入

请将我改为定制的齐格扎格印刷格式

我们用三行书写,这样,我们就这样说:

P   s   n   t   o   s   i   z   a   i   n   r
 l a e o v r m t a u t m z d i z g r n i g o m t
 e   c   e   e   c   o   e   g   p   t   f   a

(please dont edit this print out, this is required output, it is not a real zigzag, it is a customized zigzag)

最后,我们召集各行各业的竞赛,以获得由此造成的扼杀。

Psntosizainrlaeovrmtautmzdizgrnigomteceecoegptfa

我在此用假编码写出关于这个问题的算法。

it is asking about the relationship between {index} and {output row and  col}
Def:
  down = false;
  up = false; 
  r=0;
  c=0;
  char[][] output; 
there are three cases here:
case 1: 
  index % 4 == 0, it is the beginning of a down printing
  r = 0;
  output[r][c] = in.charAt(index);
  c++;
  down = true; up = false;

case 2:
  index%4 != 0 && down = true;
  r = index % 4;
  output[r][c] = in.charAt(index);
  if( r == 2){ up = true; down = false; c++;}  // when come to the last row of a down formatting

case 3:
  index%4 != 0 && up == true;
  r = 4- index%4;
  output[r][c] = in.charAt(index);
  c++;

一般性解决办法,即可将4改为n Rows+1;

虽然我认为这项工作是好的,但我对此感到不快。 是否有更明确或更快的算法来解决这一问题?

问题回答

可能会使这一问题更容易解决的一个意见是: 假设你有3行之分,希望把血压在分配物力的各行之间。 然后,如果你在四级以上,在重复这一模式之前,你会增加一、二、三和二列。 在重复这一模式之前,有5名访问过第1、2、3、4、5、4、3和2段。 更一般而言,如果你有一把千分之数,那么,将品格分配到的一套行号为1、2、3、......、k、1、k、2、2、2、2、2、2、2、2和2。

鉴于这一看法,你可能会预先准备一个包含这一周期的表格以及该周期的长短,使该守则更加清洁。 一旦有了这个表,你就可以按其特点进行循环,跟踪你所处的特性。 当你重温后,你将把大 mo克的表列,然后将该字体分上。

在假体编码中(使用单基指数):

rowTable = new array of ints length 2k - 2
for i = 1 up to k:
    rowTable[i] = i
for i = 2 up to k - 1:
    rowTable[(2k - 1) - (i - 2)] = i

resultRows = new array of strings of length k

for i = 1 up to the length of your string:
    Append the current character to resultRows[rowTable[i mod k]]

Concatenate all the entries of resultRows

这种做法并不要求你在所有不同案件中硬编码为开关说明,这意味着它可以处理任意的<条码>k,而不只是k = 3。 此外,时间非常快;运行时间是O(n + k),其中N为护堤长度,k为行数。

Hope this helps!

What do you think of this one. Original string is s -copy chars from 0 to rows-1 in a string say str

str[rows]=some impossible to occur in d original string character , like -1

- <代码>[r]至s[2r-3],载于

str[2r-2]=some impossible to occur in d original string character, -1

repeat until length is covered for these two steps, one by one.

In string str, take up every character at rows location, i.e. str[0],str[rows],str[2rows]... skipping over where str[rows] is -1. Repeat this step until length of str.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...