开发者

euler question about strings and ints

i am currently programming in euler (mathematics) the problem is i need to split the开发者_如何学Python first 10 numbers and the latst 2

: 012345678912 =

0123456789 12

i can do this by using the substring method but i need to calculate further with the first 10 numbers so what i can do is cast the string back to an int but i have no idea how to do it .. can anyone help me ?

thanks in advance


An easier way is to get the last 2 digits using the modulo operator:

012345678912 % 100 = 12

And then getting the rest by doing integer division by 100:

012345678912 // 100 = 123456789

The exact syntax needed varies depending on the language.


Depends on your programming language.

In C#, it would be the following: int.Parse(s.Substring(0, s.Length - 2));

However, I would do it mathematically as Sebastian P. detailed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜