google中国编程挑战赛-练习题之二(500分题)

qwerttyy 2005-12-08 01:55:16
继续是E文~哭~~

Problem Statement
    
A square matrix is a grid of NxN numbers. For example, the following is a 3x3 matrix:
4 3 5
2 4 5
0 1 9
One way to represent a matrix of numbers, each of which is between 0 and 9 inclusive, is as a row-major String. To generate the String, simply concatenate all of the elements from the first row followed by the second row and so on, without any spaces. For example, the above matrix would be represented as "435245019". You will be given a square matrix as a row-major String. Your task is to convert it into a String[], where each element represents one row of the original matrix. Element i of the String[] represents row i of the matrix. You should not include any spaces in your return. Hence, for the above String, you would return {"435","245","019"}. If the input does not represent a square matrix because the number of characters is not a perfect square, return an empty String[], {}.
Definition
    
Class:
MatrixTool
Method:
convert
Parameters:
String
Returns:
String[]
Method signature:
String[] convert(String s)
(be sure your method is public)
    

Constraints
-
s will contain between 1 and 50 digits, inclusive.
Examples
0)

    
"435245019"
Returns: {"435", "245", "019" }
The example above.
1)

    
"9"
Returns: {"9" }

2)

    
"0123456789"
Returns: { }
This input has 10 digits, and 10 is not a perfect square.
3)

    
"3357002966366183191503444273807479559869883303524"
Returns: {"3357002", "9663661", "8319150", "3444273", "8074795", "5986988", "3303524" }

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
...全文
742 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
qwerttyy 2005-12-10
  • 打赏
  • 举报
回复
up
kidonline 2005-12-09
  • 打赏
  • 举报
回复
大家仔细看看就能看懂。虽然比较长,但信息量很少,就是不断的重复,解释、举例。
zijida 2005-12-09
  • 打赏
  • 举报
回复
xxuu503(学会糜烂和挥霍,恐惧不安和堕落!)的伪码中,
String.toCharArray().Clone(i*temp2,(i+1)*temp2)中的temp2应为temp1.
另外至少应该有个接收的字串吧?
i三千 2005-12-09
  • 打赏
  • 举报
回复
这么多搞程序的,E文却都这么差~俺也一样
创造奇迹9999 2005-12-09
  • 打赏
  • 举报
回复
完了,今生算是和E文絕緣了!
qwerttyy 2005-12-09
  • 打赏
  • 举报
回复
up
zzd_2000_1030 2005-12-09
  • 打赏
  • 举报
回复
Public Function convert(ByVal s As String) As String()
Dim ilength As Integer, i As Integer

If Pow(Fix(Sqrt(s.Trim.Length)), 2) <> s.Trim.Length Then Return convert

ilength = Sqrt(s.Trim.Length)
Dim arr(ilength - 1) As String

For i = 0 To ilength - 1
arr(i) = Mid(s, i * ilength + 1, ilength)
Next

Return arr
End Function
qwerttyy 2005-12-09
  • 打赏
  • 举报
回复
我的答案才297分!郁闷~

using System;

public class MatrixTool
{

public String[] convert(String s)
{

int iNum = Convert.ToInt32(Math.Sqrt(s.Length));

if (iNum*iNum != s.Length) return new string[]{};

string[] sReturn = new String[iNum];
for (int i = 0; i < iNum; i++)
{
sReturn[i] = s.Substring(i*iNum,iNum);
}

return sReturn;
}
}
赖勇浩 2005-12-09
  • 打赏
  • 举报
回复
http://lanphaday.bokee.com/3821736.html

[原创]China Google Code Jam 练习题2(500分题)及参考答案
zeusvenus 2005-12-08
  • 打赏
  • 举报
回复
http://blog.csdn.net/hadelu/上做出的模拟题二的解决方法:
public class MatrixTool{

public String[] convert(String s){

int len=(int)Math.sqrt(s.length());

if(len*len==s.length())

{

String[] result=new String[len];

for( int i=0;i

{

int pos=len*i;

result[i]=s.substring(len*i,len*i+len);

}

return result;

}

return new String[]{};

}

}

feiyun0112 2005-12-08
  • 打赏
  • 举报
回复
题目要求,传一个字符窜,返回一个数组,数组的长度是字符窜的长度的开平方根
califord 2005-12-08
  • 打赏
  • 举报
回复
我们发表中国文化
兔子-顾问 2005-12-08
  • 打赏
  • 举报
回复
等中国强大了。中国的程序员拒绝回答英文提问的问题,google不得不在中国出中文版题目。万事大吉。
xxuu503 2005-12-08
  • 打赏
  • 举报
回复
根据我楼上的,伪代码如下:

1.String.length

2.int temp = String.length;
bool temp2=false;
int temp1=0;
while(temp1*temp1<temp)
{
if(temp1*temp1==temp){temp2=true;break;}
temp++;
}
if(temp2==true)
{
for(int i=0;i<temp2;i++)
{
String.toCharArray().Clone(i*temp2,(i+1)*temp2)
}
}



:)大家批判吧!
xxuu503 2005-12-08
  • 打赏
  • 举报
回复
还没看呢,就觉得头大了!
shrinerain 2005-12-08
  • 打赏
  • 举报
回复
1.获取字符串长度
2.检查长度是否是某个数a的平方,是的话把字符串平均分成a段就行了
yzg100 2005-12-08
  • 打赏
  • 举报
回复
英文太差了,看不懂呀。
dreamingnet 2005-12-08
  • 打赏
  • 举报
回复
看不懂
qwerttyy 2005-12-08
  • 打赏
  • 举报
回复
up

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧