CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

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

楼主qwerttyy(今天也要快乐!)(每天回十帖)2005-12-08 13:55:16 在 .NET技术 / C# 提问

继续是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. 问题点数:20、回复次数:19Top

1 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-08 17:46:38 得分 0

upTop

2 楼dreamingnet(刀刀)回复于 2005-12-08 17:55:51 得分 0

看不懂Top

3 楼yzg100(100学编程)回复于 2005-12-08 18:10:54 得分 0

英文太差了,看不懂呀。Top

4 楼shrinerain(圣影雨)回复于 2005-12-08 19:59:20 得分 5

1.获取字符串长度  
  2.检查长度是否是某个数a的平方,是的话把字符串平均分成a段就行了Top

5 楼xxuu503(中国没有prison break只是因为the company不让拍)回复于 2005-12-08 20:26:09 得分 0

还没看呢,就觉得头大了!Top

6 楼xxuu503(中国没有prison break只是因为the company不让拍)回复于 2005-12-08 20:33:55 得分 5

根据我楼上的,伪代码如下:  
   
  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)  
  }  
  }  
   
   
   
  :)大家批判吧!Top

7 楼wuyazhe(wyz&xyl)回复于 2005-12-08 21:15:57 得分 0

等中国强大了。中国的程序员拒绝回答英文提问的问题,google不得不在中国出中文版题目。万事大吉。Top

8 楼califord(远方)回复于 2005-12-08 21:17:51 得分 0

我们发表中国文化Top

9 楼feiyun0112(http://feiyun0112.cnblogs.com/)回复于 2005-12-08 21:51:00 得分 0

题目要求,传一个字符窜,返回一个数组,数组的长度是字符窜的长度的开平方根Top

10 楼zeusvenus()回复于 2005-12-08 22:18:07 得分 5

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[]{};  
   
  }  
   
  }  
   
  Top

11 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-09 08:52:06 得分 0

upTop

12 楼czq9966(宁录)(毛主席领导咱闹革命……)回复于 2005-12-09 09:05:22 得分 0

完了,今生算是和E文絕緣了!Top

13 楼y7967(三千)回复于 2005-12-09 10:03:55 得分 0

这么多搞程序的,E文却都这么差~俺也一样Top

14 楼zijida(左八荣,右八耻,代表挂腰间,和谐贴胸前,人挡杀人,佛挡杀佛!)回复于 2005-12-09 12:56:29 得分 0

xxuu503(学会糜烂和挥霍,恐惧不安和堕落!)的伪码中,  
            String.toCharArray().Clone(i*temp2,(i+1)*temp2)中的temp2应为temp1.  
            另外至少应该有个接收的字串吧?Top

15 楼kidonline(扬帆)回复于 2005-12-09 12:58:30 得分 0

大家仔细看看就能看懂。虽然比较长,但信息量很少,就是不断的重复,解释、举例。Top

16 楼lanphaday(恋花蝶)回复于 2005-12-09 13:20:29 得分 0

http://lanphaday.bokee.com/3821736.html  
   
  [原创]China   Google   Code   Jam   练习题2(500分题)及参考答案Top

17 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-09 14:04:00 得分 0

我的答案才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;  
  }  
  }Top

18 楼zzd_2000_1030()回复于 2005-12-09 14:10:10 得分 5

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   FunctionTop

19 楼qwerttyy(今天也要快乐!)(每天回十帖)回复于 2005-12-10 08:54:37 得分 0

upTop

相关问题

  • google中国编程挑战赛-练习题之一(1000分题)
  • google中国编程挑战赛-练习题之三(250分题)
  • google编程挑战赛试题
  • 参加Google中国编程挑战赛,赢笔记本电脑
  • 求解google编程挑战赛试题的高效算法
  • 总结一下Google编程挑战赛吧.
  • Google编程中国挑战赛第一轮Room18
  • 到底谁是google中国编程挑战赛第一名???
  • Java 网络编程---SL275练习题疑惑
  • 请问谁能弄到《java编程思想》的书后练习题答案?

关键词

  • ilength
  • matrix
  • square
  • represent
  • arr
  • row
  • temp
  • element
  • number
  • length

得分解答快速导航

  • 帖主:qwerttyy
  • shrinerain
  • xxuu503
  • zeusvenus
  • zzd_2000_1030

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo