编写了第二个题目,总分500,得分499.76分。估计这个计分还根据时间来的。时间越长得分越少。这次我先编译好直接copy的。
        题目:
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" }

我的代码:

public class MatrixTool
    {
        public MatrixTool()
        {
        
        }

        public string[] convert(string s)
        {
            string[] returnValues;
            //开平方
            if (s.Length>50)
            {
                returnValues = new string[1]{"This input Length overflow."};
            }
            else
            {
                double d = System.Math.Sqrt((double)s.Length);
                double di = System.Math.Ceiling(d);
                if (d!=di)
                {
                    returnValues = new string[1]{"This input has "+s.Length.ToString()+" digits, and "+s.Length.ToString()+" is not a perfect square."};
                }
                else
                {
                    try
                    {
                        System.Convert.ToDouble(s);
                    }
                    catch
                    {
                        returnValues = new string[1]{"This input hasn't numbers."};
                        return returnValues;
                    }
                    int i = System.Convert.ToInt32(di);
                    int k=0;
                    //转换
                    returnValues = new string[i];
                    for (int j=0 ;j<i;j++)
                    {
                        returnValues[j] = s.Substring(k,i);
                        k = i*(j+1)-1;
                    }
                }
            }
            return returnValues;
        }
    
    }

转载于:https://www.cnblogs.com/pfengk/archive/2005/12/09/293986.html

参加Google™ Code Jam - 中国编程挑战赛(2)相关推荐

  1. 入职顶级互联网公司,竞争性编程是必须的吗?Google code jam King赛前采访(附有视频)

    主持人:你能告诉我一些关于你自己的事吗 受访者:就像我决定从事的竞争性编程一样,竞争性编程我不仅参加了那些比赛,高中时我在美国参加Google Code Jam,因为我进入了决赛,这是我生命中的一部分 ...

  2. Google Code Jam程序设计大赛中国人获冠亚军

    来自 Google的官方消息,今年的Google Code Jam程序设计大赛,冠亚军都被中国人获得. 冠军是楼天城(Tiancheng Lou,来自清华大学计算机系),奖金$10,000.亚军朱泽园 ...

  3. 【Google Code Jam】Millionaire

    题目描述 Google Code Jam 2008APAC local onsites C 最开始你有X元钱,要进行M轮赌博.每一轮赢的概率为P,你可以选择赌与不赌,如果赌也可以将所持的任意一部分钱作 ...

  4. [Google Code Jam] 2013-1A-C Good Luck 解法

    问题的陈述在:https://code.google.com/codejam/contest/2418487/dashboard#s=p2&a=1, 官方的分析在:https://code.g ...

  5. Google Code Jam Round 1A 2015 解题报告

    题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...

  6. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  7. Google Code Jam 2014 -- C

    题目链接:https://code.google.com/codejam/contest/2974486/dashboard#s=p2 比赛的时候想出了小数据的处理办法, 位压缩然后枚举+BFS, 但 ...

  8. Google Code Jam 2017 资格赛

    https://code.google.com/codejam/contest/3264486/dashboard#s=p3 Oversized Pancake Flipper (1)问题描述: Pr ...

  9. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

最新文章

  1. 地图样式自定义_干货在线 | ArcGIS中定义图框样式
  2. java 不知道键值名_java-如果您知道曲线名称和原始私钥/点,如...
  3. 20155222 2016-2017-2 《Java程序设计》第10周学习总结
  4. JavaWeb:CSS层叠样式表
  5. 蓝桥杯java第八届第四题--魔方状态
  6. 买空long position、卖空short position
  7. python3.7下载教程视频_视频 | 我选择Python3.7来学习!顺便把教程分享给大家
  8. clientHeight.offsetHeight.scrollHeight等的区别
  9. netty 5.0 源码分析(1)-----ButeBuf
  10. 数字证书驱动_网上申报中环CA数字证书更新流程(图解)
  11. oracle创建哈希索引,ORACLE10g新特性——全局HASH分区索引
  12. 远程诊断技术在汽车 OTA 刷新应用的研究
  13. 让cajviewer记住正在浏览的文献,下次启动时自动打开上次浏览的文献
  14. mac开机启动项怎么设置,苹果电脑开机启动项在哪里设置
  15. C++求解一元三次方程的实根
  16. linux查看ssh进程命令,查看linux ssh服务信息及运行状态方法
  17. HC05蓝牙模块与stm32通信
  18. mysql数据导入报错1265
  19. 强网杯2019(高明的黑客强网先锋上单)
  20. Java中print()\println()\printf()的区别及用法

热门文章

  1. 嵌入式开发之hi3519---PCIE DMA
  2. Oracle 快速插入1000万条数据的实现方式
  3. nginx 禁止IP访问服务器和非法域名绑定你的IP
  4. WPF 第一个创建的窗体会作为Application.Current.MainWindow
  5. Visual Studio 2008 可扩展性开发(三):Add-In运行机制解析(下)
  6. java 数据存储到什么地方?
  7. 在IIS中删除ETag的方法
  8. js中String的常用扩展
  9. Effective C++ 小笔记:条款13-17(第三章)
  10. SizeOf与Structure与Managed Code