以下是我的代码,很简单的,没有什么好介绍,也用不着解释吧?
这个答案通过了symtem test,也就说,这是无错的.
#include
#include
#include
using namespace std;
class MatrixTool
{
public:
MatrixTool(){};
~MatrixTool(){};
vector
{
m_vec.clear();
if( s.empty() )
{
return m_vec;
}
int len = s.size();
if( len == 1)
{
m_vec.push_back( s );
return m_vec;
}
double squareroot = sqrt( len );
if( squareroot - (double)(int)squareroot < 0.0000001 )
{
int sr = (int)squareroot;
for( int i = 0; i < len; i += sr )
{
m_vec.push_back( s.substr( i, sr ) );
}
}
return m_vec;
};
private:
vector
};
以下是原题:
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 vector
Definition
Class:
MatrixTool
Method:
convert
Parameters:
string
Returns:
vector
Method signature:
vector
(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.
你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=3821736
| 报名参加Google Code Jam。呵呵! | BigGuo |
| 报名参加Google Code Jam。呵呵! | BigGuo |
| The Matrix | emptysniper |
| Google提供的服务清单 | zq888888 |
| Google提供的服务清单 | zq888888 |