Rust Language Solution Question 1

Source: Internet
Author: User

/* Compare for a moment

: http://blog.csdn.net/iilovetopview/article/details/43745059

It's fast to find the D language.

*/

Use Std::time::d uration::D uration;

Use Std::num::int;
Use Std::collections::hashmap;
Use Std::collections::hash::map;


Pub struct Va {
Pub ac:vec<usize>
Pub aa:hashmap<usize, Usize>
}

fn Main () {
Let R = Duration::span (FNX);
println! ("Time: {} milliseconds", R.num_milliseconds ());
}

fn FNX ()
{
Let (Mut pos,mut N, mut count) = (0,1,0);

while (n >0)
{
Let Mut vc = Va{ac:vec![],aa:hashmap::new (),};

pos = Fx (N,VC);

if (n = = pos)
{
Count +=1;
println! ("N is: {0}, Fn (n) is:{1}", N,pos);
if (count >1) {break;}
}
N+=1;
if (n >200000) {break;} //
}

}


fn Fx (N:usize,mut va:va), usize
{
Let (Mut i,mut y,mut L) = (0,0,0);
Let mut x = n;
while (x>=1)
{
y=x%10;
Va.aa.insert (I,y);
Va. Ac.push (y);
x/= 10;
I+=1;
}

Let mut m = Va. Ac.len ()-1;

Let (mut result, mut h) = (0,0);
H =va.aa[m];
if (N%gpow (m) = = 0) {return FnA (h,m);}
else {return FnA (h,m) +FNB (M-1,VA);}
}

fn FnA (h:usize,m:usize)->usize
{
if (h = = 0) {return 0;}
else if (h==1) {if (M = = 0) {return 1;} else {return M*gpow (m-1) +1;}}
else {if (M = = 0) {return 1;} else {return Gpow (m) +h*m*gpow (m-1);}}
}


fn FnB (M:usize,mut va:va)->usize

{

...//code slightly

return sum + FnB (M-1,VA);
}

fn Gpow (m:usize)->usize
{
Return 10.pow (m);

}


Rust Language Solution Question 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.