Urgent. digital restructuring computing problems

Source: Internet
Author: User
Urgent. digital restructuring calculation problem description:
Now there is a set of numbers that need to calculate the total number after reorganization, and calculate the total number with the fastest speed.
Numbers are not necessarily given, but may be other numbers.
Number:
Example 1
1-> 0123
2-> 01234
3-> 678
Total: 60


Example 2
1-> 0123456789
2-> 0123456789
3-> 01234
Total: 500


Write a method to calculate the total number after reorganization and the number after reorganization.


Reply to discussion (solution)

Don't understand what you mean
It is best to give an example

Can't understand ~~~~

Example:

1-> 0
2-> 01
3-> 01

The restructured number is 000,001,010,011, and the total number is 4

What does this mean?

$ Ar = array ('123', '123', '123',); print_r (foo ($ ar); function foo (& $ ar, $ I = 0) {$ res = array (); if ($ I + 1
 
  
Array
  
(
[0] => 006
[1] => 007
[2] => 008
[3] => 016
[4] => 017
[5] => 018
[6] => 026
[7] => 027
[8] => 028
[9] => 036
[10] => 037
[11] => 038
[12] => 046
[13] => 047
[14] => 048
[15] = & gt; 106
[16] = & gt; 107
[17] => 108.
[18] = & gt; 116
[19] = & gt; 117
[20] = & gt; 118
[21] = & gt; 126
[22] = & gt; 127
[23] = & gt; 128
[24] = & gt; 136
[25] = & gt; 137
[26] = & gt; 138
[27] = & gt; 146
[28] = & gt; 147
[29] = & gt; 148
[30] => 206.
[31] = & gt; 207
[32] = & gt; 208
[33] = & gt; 216
[34] = & gt; 217
[35] = & gt; 218
[36] = & gt; 226
[37] = & gt; 227
[38] = & gt; 228
[39] = & gt; 236
[40] = & gt; 237
[41] = & gt; 238
[42] = & gt; 246
[43] = & gt; 247
[44] = & gt; 248
[45] = & gt; 306
[46] = & gt; 307
[47] = & gt; 308
[48] = & gt; 316
[49] = & gt; 317
[50] = & gt; 318
[51] = & gt; 326
[52] = & gt; 327
[53] = & gt; 328
[54] = & gt; 336
[55] = & gt; 337
[56] = & gt; 338
[57] = & gt; 346
[58] = & gt; 347
[59] = & gt; 348
)

If you do not consider repetition, isn't this an arrangement or combination?
1-> 0123
2-> 01234
3-> 678
Total = A () * A () = 4*5*3 = 60

If you do not consider repetition, isn't this an arrangement or combination?
1-> 0123
2-> 01234
3-> 678
Total = A () * A () = 4*5*3 = 60
Code?

Echo strlen ('123') * strlen ('123') * strlen ('123 ');//?? Is this the fastest?

   


Oh! Just calculate the number of combinations ?! I thought it required all the combinations.

$ar = array('0123456789', '0123456789', '01234');echo array_product(array_map('strlen', $ar));

In fact, all of your methods are correct. I just didn't think of the fastest... I am confused. thank you...

It seems that I still want to read the PHP manual, and I was killed by the xu version.

I found a strange problem in the array. I don't know if I have a problem with writing.

$strArr = array(    1 => 0, 3 => 1, 6 => 2, 10 => 3, 15 => 4, 21 => 5, 28 => 6, 36 => 7, 45 => 8,    55 => 9, 63 => 10, 69 => 11, 73 => 12, 75 => 13, 75 => 14, 73 => 15, 69 => 16,    63 => 17, 55 => 18, 45 => 19, 36 => 20, 28 => 21, 21 => 22, 15 => 23, 10 => 24, 6 => 25,    3 => 26, 1 => 27);echo $str = '1,2,3,6,7,25,23,15,18'."\n";$sArr = explode(',',$str);foreach($sArr as $v){    echo array_search($v,$strArr)."\n";}


Result:
1,2,3,6,7,25,23,15,186157355Array(    [1] => 27    [3] => 26    [6] => 25    [10] => 24    [15] => 23    [21] => 22    [28] => 21    [36] => 20    [45] => 19    [55] => 18    [63] => 17    [69] => 16    [73] => 15    [75] => 14)


Why are there none of my 0-13 accounts ???

What does 0-13 mean?

Your $ strArr array key name is repeated, so the subsequent one overwrites the previous one. Print_r ($ strArr.

$ StrArr = array (
1 => 0,
3 => 1,
6 => 2,
10 => 3,
15 => 4,
21 => 5,
28 => 6,
36 => 7,
45 => 8,
55 => 9,
63 => 10,
69 => 11,
73 => 12,
75 => 13,
75 => 14,
73 => 15,
69 => 16,
63 => 17,
55 => 18,
45 => 19,
36 => 20,
28 => 21,
21 => 22,
15 => 23,
10 => 24,
6 => 25,
3 => 26,
1 => 27
);
The red subscript will overwrite the existing subscript above.

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.